我这样定义一个成员:
@property (nonatomic, retain) NSIndexPath *deletingIndexPath; //记录当前需要删除的行
并在
中赋值- (void)tableView:(UITableView *)atableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
...
deletingIndexPath = indexPath;
...
}
并在另一个回调函数中使用它
NSArray *deleteIndexPaths = [NSArray arrayWithObjects:deletingIndexPath,nil];
[self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
然后它崩溃了...
在模拟器中它说
2012-07-10 16:56:54.887 p[20972:16a03] *** Assertion failure in -[NSIndexPath row], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableViewSupport.m:2606
2012-07-10 16:56:54.898 p[20972:16a03] Uncaught exception: Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.
谁能告诉我为什么?
最佳答案
你在 ARC 吗?如果不是,您必须保留您的实例。您分配的那个在您可以使用之前自动释放。你可以使用 self.deletingIndexPath = indexPath;
这样属性就会保留实例
关于ios - 我想记住一个 (NSIndexPath *)indexPath 以便以后删除,但是崩溃了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11410465/