【问题标题】:Delete row from uitableview crashes从 uitableview 崩溃中删除行
【发布时间】:2010-02-09 14:11:23
【问题描述】:

我只是尝试使用以下代码从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”。) 有人知道为什么吗?

【问题讨论】:

  • 你在 objc_exception_throw 上有符号断点吗?如果没有,请尝试添加它并查看执行停止的位置。
  • 另外,如果您在代码前面放置 4 个空格,则格式会更好,更易于阅读。
  • 好的,感谢您格式化我的代码。执行在这里停止:+[NSException raise:format:arguments:] ...有什么想法吗?
  • 控制台有错误说明吗?

标签: iphone uitableview crash row


【解决方案1】:

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

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

indexPath.section 比删除前小一。

【讨论】:

  • 是的,在删除这一行之前,我必须先从数组中删除对象。知道它有效!谢谢
猜你喜欢
  • 1970-01-01
  • 2012-03-11
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多