Delete row from uitableview crashes

让人想犯罪 __ 提交于 2020-01-15 04:44:06

问题


I simply try to delete a row from a UITableView with the following code:

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

The problem is that my app crashes. (GDB: Program received signal: "EXC_BAD_INSTRUCTION".) Anybody know why?


回答1:


You probably need to change the number returned in

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section

for the indexPath.section to be one lower than before the deletion.



来源:https://stackoverflow.com/questions/2229626/delete-row-from-uitableview-crashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!