【发布时间】:2012-07-26 09:02:30
【问题描述】:
我对删除 UITableView 中的行的概念有一些小问题。用户删除一行后我不想触发:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
相反,我想更改已编辑的单元格文本和背景而不隐藏它。我的方法效果很好:
if (editingStyle == UITableViewCellEditingStyleDelete) { NSMutableArray *previous_points = [self.trip_arrayOfAllPoints mutableCopy]; [previous_points removeObjectAtIndex:indexPath.row]; self.trip_arrayOfAllPoints = nil; self.trip_arrayOfAllPoints = [[NSMutableArray alloc] initWithCapacity:[previous_points count]]; self.trip_arrayOfAllPoints = [previous_points mutableCopy]; self.trip_arrayOfAllPointsEDITED = [[NSMutableArray alloc] initWithCapacity:[previous_points count]]; self.trip_arrayOfAllPointsEDITED = [previous_points mutableCopy]; //[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; self.trip_isArrayOfAllPointsEDITED = YES; }
但在删除一行后,它不会在当前单元格上提交消失“DELETE”标签的动画。有没有办法绕过“Apple方式”删除行?
编辑 - 我已经解决了
它非常简单明了。只需将 deleteRowsAtIndexPaths 替换为:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
在这个“删除”动画消失后,单元格仍在原处。
【问题讨论】:
标签: iphone objective-c ios uitableview