线程 1:EXC_BAD_ACCESS(代码=1,地址=0x14) [英] thread 1:EXC_BAD_ACCESS (code=1, address=0x14)

查看:29
本文介绍了线程 1:EXC_BAD_ACCESS(代码=1,地址=0x14)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建从 tableview 中删除行的功能,这就是我做到的.错误来自

I'm trying to create the capability of deleting rows from a tableview and this is how I did it. The error is coming from the

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] withRowAnimation:UITableViewRowAnimationFade];

非常感谢任何帮助.谢谢!

Any help would be very much appreciated. Thank you!

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


    if (editingStyle == UITableViewCellEditingStyleDelete) {

        [self.homeworkArray removeObjectAtIndex:indexPath.row];

        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

    [self.tableView reloadData];

}

推荐答案

arrayWithObjects: 方法需要一个 nil 来终止列表,所以你需要说 -

the arrayWithObjects: method requires a nil to terminate the list, so you need to say -

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];
}

或者更简单,使用 arrayWithObject:

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

或者如@rmaddy 指出的那样,使用数组字面量语法 -

Or as @rmaddy points out, use array literal syntax -

[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

此外,您不需要 reloadData 调用 - deleteRowsAtIndexPaths 将负责更新表视图中的相关行.

Also, you don't need the reloadData call - deleteRowsAtIndexPaths will take care of updating the relevant rows in the table view.

这篇关于线程 1:EXC_BAD_ACCESS(代码=1,地址=0x14)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆