0

我想在不使用以下数据源方法的情况下从表视图中删除一行。怎么做?

- (void) tableView : (UITableView *)tableView 
commitEditingStyle : (UITableViewCellEditingStyle)editingStyle 
 forRowAtIndexPath : (NSIndexPath *)indexPath 
4

3 回答 3

3

怎么样[UITableView deleteRowsAtIndexPaths: withRowAnimation:]

(我已经为您链接了 Apple 的文档)。

@Scar 的想法也不错,但这会刷新整个表格,如果用户滚动到表格底部并且刷新将他们带到顶部,这可能会对用户造成一点干扰。

于 2012-08-09T04:32:20.293 回答
3

没那么简单,您必须使用 UITableView 原子地执行此操作

[_tableView beginUpdates]; // <-- pretty important

long selectedRow = _tableView.selectedRow;

[_tableView removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:selectedRow] withAnimation:NSTableViewAnimationSlideUp];

//then remove your object from the array
[((NSMutableArray*) _searchResults) removeObjectAtIndex:selectedRow];

[_tableView endUpdates];

这可以防止在更新数组时调用委托方法。

于 2012-08-09T04:42:18.353 回答
1

从模型中删除该行并调用-deleteRowsAtIndexPaths:withRowAnimation:.

于 2012-08-09T04:31:56.690 回答