1

我这样定义一个成员:

@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.

谁能告诉我为什么?

4

1 回答 1

2

你在ARC吗?如果不是,您必须保留您的实例。您分配的那个是在您使用它之前自动释放的。您可以使用self.deletingIndexPath = indexPath;这样该实例将由该属性保留

于 2012-07-10T09:38:15.713 回答