作者j5307 (JJ)
看板MacDev
标题[问题] 关於表格删除问题
时间Fri Sep 21 01:12:07 2012
第一次发文如有不妥麻烦告知感恩
目前正在做关於录影存档的程式 碰上於删除表格後所发生crash的问题
- (void)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *path = [dirs objectAtIndex:0];
NSString *FileName =[[[NSString alloc]initWithString:path]
stringByAppendingPathComponent:@"/"];
NSInteger sumnumber=0,partnumber=0;
//底下的video是一维阵列存放影片 我在读video内容时将section内的row数加总
for (int j=0; j<indexPath.section; j++) {
//recordrownumber记录各section的row数
partnumber=[[recordrownumber objectAtIndex:j] integerValue];
sumnumber=sumnumber+partnumber;
}
partnumber=[indexPath row];
sumnumber+=partnumber;
//移除video内存放影片的路径
NSString *firstFileName = [video objectAtIndex:sumnumber];
FileName=[FileName stringByAppendingPathComponent:firstFileName];
[[NSFileManager defaultManager]removeItemAtPath:FileName error:nil];
[video removeObjectAtIndex:sumnumber];
[self.tableView deleteRowsAtIndexPaths:
[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationLeft];
}
错误的是这一行(当我把这行注解掉就不会crash)
[self.tableView deleteRowsAtIndexPaths:
[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationLeft];
其错误原因
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Invalid update: invalid number of rows in section 3. The number of
rows contained in an existing section after the update (6) must be equal to
the number of rows contained in that section before the update (6), plus or
minus the number of rows inserted or deleted from that section (0 inserted,
1 deleted) and plus or minus the number of rows moved into or out of that
section (0 moved in, 0 moved out).'
*** First throw call stack:
(0x326bf88f 0x34715259 0x326bf789 0x37fe43a3 0x3219dd1d 0x3219b8f3 0x3221426b
0x405e7 0x3222e08d 0x326193fd 0x32101e07 0x32101dc3 0x32101da1 0x32101b11
0x32102449 0x3210092b 0x32100319 0x320e6695 0x320e5f3b 0x3176d22b 0x32693523
0x326934c5 0x32692313 0x326154a5 0x3261536d 0x3176c439 0x32114cd5 0x3e10d
0x3e0a8)terminate called throwing an exception(lldb)
网路上找了很多资料 现在一个头两个大完全不知道该怎麽修改才是
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.174.90.198
1F:→ j5307:另外我的section数 大於1 09/21 17:25
2F:→ chd75131:因为你只是把tableview上的cell删除 你使用的datasource 09/22 01:35
3F:→ chd75131:并没有跟着更新 所以会造成你datasource的数目会大於实际 09/22 01:36
4F:→ chd75131:tableview上所显示的资料 所以当你delete row时记得 09/22 01:37
5F:→ chd75131:module也要更新 然後最好用[tableview beginupdate] 09/22 01:38
6F:→ chd75131:跟[tableview endupdate]包起来 09/22 01:38
7F:→ j5307:我已经解决这问题了 谢谢 09/22 10:21