【问题标题】:Deleting Row in TableViewController - "unrecognized selector" crash删除 TableViewController 中的行 - “无法识别的选择器”崩溃
【发布时间】:2015-06-24 19:11:28
【问题描述】:

我试图从作为 MutableArray 的 productArray 属性中删除 tableView 中的两个“产品”。

 [self.productsArray removeObjectAtIndex:indexPath.row];

    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

我在控制台中收到此错误:

-[__NSArrayI removeObjectAtIndex:]:无法识别的选择器发送到实例 0x7ff6f850e410 2015-06-24 15:09:24.568 NavCtrl[17333:8660630] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSArrayI removeObjectAtIndex:]:无法识别的选择器发送到实例 0x7ff6f850e410”

查看调试器,似乎 indexPath 属性为 NULL。我猜这是为什么我的代码崩溃的一个很好的候选,但是我不知道为什么 indexPath 没有我删除的行的值。

感谢任何帮助,如果需要更多信息,请告诉我。

【问题讨论】:

    标签: ios


    【解决方案1】:
    [__NSArrayI removeObjectAtIndex:]:  indicates that your array is not mutable!
    

    确定数组是否确实是可变的。如果是,请尝试先删除单元格,然后再从数组中删除对象。

    【讨论】:

      【解决方案2】:

      在吗?

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

      你可以粘贴所有代码吗?

      试试这个来测试:

      NSIndexpath *idxPath = [NSIndexPath indexPathForRow:0 inSection:0];
          [self.productsArray removeObjectAtIndex:idxPath];
      
          [tableView beginUpdates];
          [tableView deleteRowsAtIndexPaths:@[idxPath] withRowAnimation:UITableViewRowAnimationFade];
          [tableView endUpdates];
      

      【讨论】:

        猜你喜欢
        • 2016-07-05
        • 2012-09-20
        • 1970-01-01
        • 2015-12-04
        • 1970-01-01
        • 2015-01-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多