[問題] 關於表格刪除問題
第一次發文如有不妥麻煩告知感恩
目前正在做關於錄影存檔的程式 碰上於刪除表格後所發生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
→
09/21 17:25, , 1F
09/21 17:25, 1F
→
09/22 01:35, , 2F
09/22 01:35, 2F
→
09/22 01:36, , 3F
09/22 01:36, 3F
→
09/22 01:37, , 4F
09/22 01:37, 4F
→
09/22 01:38, , 5F
09/22 01:38, 5F
→
09/22 01:38, , 6F
09/22 01:38, 6F
→
09/22 10:21, , 7F
09/22 10:21, 7F
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章