从 uitableview 崩溃中删除行

发布于 2024-08-20 09:51:38 字数 501 浏览 3 评论 0原文

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や莫失莫忘 2024-08-27 09:51:38

您可能需要将 indexPath.section 返回的数字更改

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

为比删除之前小 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文