jjzjj

ios - 怎么可能tableView :commitEditingStyle:forRowAtIndexPath: be called with a nil indexPath?

coder 2023-07-29 原文

我终于找到了一个奇怪的崩溃。这是由 tableView:commitEditingStyle:forRowAtIndexPath: 调用时使用 nil indexPath 引起的。但这怎么可能呢?

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // DEBUG
        if (indexPath == nil) {
            NSLog(@"Deleting row at nil indexPath in %@", self);
        }
        [self deleteItemAtIndexPath:indexPath fromTableView:tableView];
    }
}

这是堆栈跟踪:

6    XXX     -[ListViewController tableView:commitEditingStyle:forRowAtIndexPath:] (ListViewController.m:427)
7    UIKit   -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 85
8    UIKit   -[UIApplication sendAction:to:from:forEvent:] + 73
9    UIKit   -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 31
10   UIKit   -[UIControl sendAction:to:forEvent:] + 45
11   UIKit   -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
12   UIKit   -[UIApplication sendAction:to:from:forEvent:] + 73
13   UIKit   -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 31
14   UIKit   -[UIControl sendAction:to:forEvent:] + 45
15   UIKit   -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
16   UIKit   -[UIControl touchesEnded:withEvent:] + 489
17   UIKit   -[UIWindow _sendTouchesForEvent:] + 525
18   UIKit   -[UIApplication sendEvent:] + 381
19   UIKit   _UIApplicationHandleEvent + 6155
20   GraphicsServices    _PurpleEventCallback + 591
21   CoreFoundation  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
22   CoreFoundation  __CFRunLoopDoSources0 + 213
23   CoreFoundation  __CFRunLoopRun + 647
24   CoreFoundation  CFRunLoopRunSpecific + 357
25   CoreFoundation  CFRunLoopRunInMode + 105
26   GraphicsServices    GSEventRunModal + 75
27   UIKit   UIApplicationMain + 1121
28   XXX     main (main.m:16)
29   XXX     start + 40

最佳答案

异常是由于索引处存在数据但索引路径已被删除。您需要删除索引处的数组对象。

尝试以下操作:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
   {
      if (editingStyle == UITableViewCellEditingStyleDelete) 
      {
         [self deleteItemAtIndexPath:indexPath fromTableView:tableView];
         NSMutableArray * tempArray = [yourDataArray mutableCopy];
        [tempArray removeObjectAtIndex: indexPath.row];
         yourDataArray = tempArray;
        [tableView reloadData];
      }
   }

关于ios - 怎么可能tableView :commitEditingStyle:forRowAtIndexPath: be called with a nil indexPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13167353/

有关ios - 怎么可能tableView :commitEditingStyle:forRowAtIndexPath: be called with a nil indexPath?的更多相关文章

  1. ruby - 如何以所有可能的方式将字符串拆分为长度最多为 3 的连续子字符串? - 2

    我试图获取一个长度在1到10之间的字符串,并输出将字符串分解为大小为1、2或3的连续子字符串的所有可能方式。例如:输入:123456将整数分割成单个字符,然后继续查找组合。该代码将返回以下所有数组。[1,2,3,4,5,6][12,3,4,5,6][1,23,4,5,6][1,2,34,5,6][1,2,3,45,6][1,2,3,4,56][12,34,5,6][12,3,45,6][12,3,4,56][1,23,45,6][1,2,34,56][1,23,4,56][12,34,56][123,4,5,6][1,234,5,6][1,2,345,6][1,2,3,456][123

  2. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  3. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  4. ruby - Ruby 中的隐式返回值是怎么回事? - 2

    所以我开始关注ruby​​,很多东西看起来不错,但我对隐式return语句很反感。我理解默认情况下让所有内容返回self或nil但不是语句的最后一个值。对我来说,它看起来非常脆弱(尤其是)如果你正在使用一个不打算返回某些东西的方法(尤其是一个改变状态/破坏性方法的函数!),其他人可能最终依赖于一个返回对方法的目的并不重要,并且有很大的改变机会。隐式返回有什么意义?有没有办法让事情变得更简单?总是有返回以防止隐含返回被认为是好的做法吗?我是不是太担心这个了?附言当人们想要从方法中返回特定的东西时,他们是否经常使用隐式返回,这不是让你组中的其他人更容易破坏彼此的代码吗?当然,记录一切并给出

  5. ruby - 怎么来的(a_method || :other) returns :other only when assigning to a var called a_method? - 2

    给定以下方法:defsome_method:valueend以下语句按我的预期工作:some_method||:other#=>:valuex=some_method||:other#=>:value但是下面语句的行为让我感到困惑:some_method=some_method||:other#=>:other它按预期创建了一个名为some_method的局部变量,随后对some_method的调用返回该局部变量的值。但为什么它分配:other而不是:value呢?我知道这可能不是一件明智的事情,并且可以看出它可能有多么模棱两可,但我认为应该在考虑作业之前评估作业的右侧...我已经在R

  6. ruby-on-rails - 我该怎么办 :remote location validation with CarrierWave? - 2

    我在我的Rails3示例应用程序上使用CarrierWave。我想验证远程位置上传,因此当用户提交无效URL(空白或非图像)时,我不会收到标准错误异常:CarrierWave::DownloadErrorinImageController#createtryingtodownloadafilewhichisnotservedoverHTTP这是我的模型:classPaintingtrue,:length=>{:minimum=>5,:maximum=>100}validates:image,:presence=>trueend这是我的Controller:classPaintingsC

  7. 电脑0x0000001A蓝屏错误怎么U盘重装系统教学 - 2

      电脑0x0000001A蓝屏错误怎么U盘重装系统教学分享。有用户电脑开机之后遇到了系统蓝屏的情况。系统蓝屏问题很多时候都是系统bug,只有通过重装系统来进行解决。那么蓝屏问题如何通过U盘重装新系统来解决呢?来看看以下的详细操作方法教学吧。  准备工作:  1、U盘一个(尽量使用8G以上的U盘)。  2、一台正常联网可使用的电脑。  3、ghost或ISO系统镜像文件(Win10系统下载_Win10专业版_windows10正式版下载-系统之家)。  4、在本页面下载U盘启动盘制作工具:系统之家U盘启动工具。  U盘启动盘制作步骤:  注意:制作期间,U盘会被格式化,因此U盘中的重要文件请注

  8. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  9. ruby - EventMachine - 你怎么知道你是否落后了? - 2

    我正在研究使用EventMachine支持的twitter-streamruby​​gem来跟踪和捕获推文。我对整个事件编程有点陌生。我如何判断我在事件循环中所做的任何处理是否导致我落后?有没有简单的检查方法? 最佳答案 您可以通过使用周期性计时器并打印出耗时来确定延迟。如果您使用的是1秒的计时器,您应该已经过了大约1秒,如果它更长,您就知道您正在减慢react器的速度。@last=Time.now.to_fEM.add_periodic_timer(1)doputs"LATENCY:#{Time.now.to_f-@last}"@

  10. ruby - 如果它是标点符号,我怎么能从字符串中删除最后一个字符,在 ruby​​ 中? - 2

    啊,正则表达式有点困惑。我正在尝试删除字符串末尾所有可能的标点符号:ifstr[str.length-1]=='?'||str[str.length-1]=='.'||str[str.length-1]=='!'orstr[str.length-1]==','||str[str.length-1]==';'str.chomp!end我相信有更好的方法来做到这一点。有什么指点吗? 最佳答案 str.sub!(/[?.!,;]?$/,'')[?.!,;]-字符类。匹配这5个字符中的任何一个(注意,。在字符类中并不特殊)?-前一个字符或组

随机推荐