【发布时间】:2015-05-10 22:34:04
【问题描述】:
我在向左滑动时实现了一个 tableView 和一个删除(正常方式)。当我点击删除按钮时,记录会从数据库中删除,但不会从视图中删除。我想立即将其从桌子上删除。为了看到记录已被删除,我需要返回上一个视图并再次返回 tableView,然后记录才消失。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NewArt *currArt = [self.lN_Dep objectAtIndex:indexPath.row];
self.deptsub = [self.lN_Dep subarrayWithRange:NSMakeRange(indexPath.row, (self.lN_Dep.count - indexPath.row))];
self.selectedURL = [currArt.link absoluteString];
self.selected_ID = (NSString *)currArt.art_ID;
self.selectedArt = currArt;
NSArray *ArrayOfArtIDs_old = [ArtString componentsSeparatedByString:@","];
NSMutableArray *ArrayOfArtIDs_new = [[NSMutableArray alloc]init];
ArrayOfArIDs_new = [[NSMutableArray alloc] initWithArray:ArrayOfArtIDs_old];
for (NSString *item in ArrayOfArtIDs_old) {
if ([item isEqualToString:self.selected_ID]) {
[ArrayOfArtIDs_new removeObject:self.selected_ID];
NSString *updateArt = [self updatedArtIDs:ArrayOfArtIDs_new];
if ([updateArt isEqualToString:@"true"]) {
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[_lN_Dep removeObjectAtIndex:indexPath.row];
//[_lN_Dep removeObject:indexPath];
[self.tableView endUpdates];
}
}
}
[self bookMarkedFeed];
}
当我按下删除时程序中断并且这一行被突出显示。
[_lN_Dep removeObject:indexPath];
或
[_lN_Dep removeObjectAtIndex:indexPath.row];
【问题讨论】:
标签: ios objective-c uitableview