从uitableview崩溃中删除行

Sea*_*ean 2 iphone crash row uitableview

我只是尝试UITableView使用以下代码从a中删除一行:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (editingStyle == UITableViewCellEditingStyleDelete)
     {
         [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
     }
}
Run Code Online (Sandbox Code Playgroud)

问题是我的应用程序崩溃了.(GDB:程序收到信号:"EXC_BAD_INSTRUCTION".)有人知道为什么吗?

Fel*_*oux 8

您可能需要更改返回的数字

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)

因为它indexPath.section比删除前低一个.

  • 是的,我必须先删除我的数组中的对象,然后再删除此行.知道它有效!谢谢 (3认同)