代码之家  ›  专栏  ›  技术社区  ›  esilver rmaddy

如何确定uiscrollview崩溃是在我的代码中还是在苹果的代码中?

  •  5
  • esilver rmaddy  · 技术社区  · 14 年前

    我定期在我的iPhone上运行的一个调试版本上重新生成一个崩溃,它涉及一个uiscrollview,堆栈框架中没有我的代码。我想知道这是我的代码中的错误还是苹果的错误,我无法查询苹果的错误数据库来查看是否已经报告了。回溯显示:

    #0  0x30218060 in ___forwarding___ ()
    #1  0x3020eda0 in __forwarding_prep_0___ ()
    #2  0x309c4ce8 in -[UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded] ()
    #3  0x3025af60 in -[NSObject performSelector:withObject:] ()
    #4  0x3098ea94 in -[UIAnimator stopAnimation:] ()
    #5  0x3098e5a8 in -[UIAnimator(Static) _advance:] ()
    #6  0x3098e460 in LCDHeartbeatCallback ()
    #7  0x32047fe8 in HeartbeatVBLCallback ()
    #8  0x32a1c3ec in IOMobileFramebufferNotifyFunc ()
    #9  0x3188a74c in IODispatchCalloutFromCFMessage ()
    #10 0x3020d0b0 in __CFMachPortPerform ()
    #11 0x30254a76 in CFRunLoopRunSpecific ()
    #12 0x3025416a in CFRunLoopRunInMode ()
    #13 0x320452a4 in GSEventRunModal ()
    #14 0x308f037c in -[UIApplication _run] ()
    #15 0x308eea94 in UIApplicationMain ()
    #16 0x0000280c in main (argc=1, argv=0x2ffff58c) at /Users/esilver/Documents/Husband Material/main.m:14
    

    问题显然出在 UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded . GDB报道:

    -[MyViewController respondsToSelector:]: message sent to deallocated instance 0x5d77ad0
    

    在MyViewController中,我确实调用了滚动TableView:

    [self.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];  
    

    因为它是动画的,所以很明显,在滚动动画完成之前,视图可能会从导航控制器弹出。似乎应该是uiview的工作,以便在卸载时取消或等待任何挂起的滚动操作。因此,我认为这是苹果代码中的一个缺陷。

    或者我弄错了,是否有某种检查我的视图必须在卸载之前检查它是否滚动,或者我是否完全误读了这个崩溃?

    仅供参考,这个bug只在内存不足的情况下出现,即我已经开始接收didReceiveMemoryWarning回调。

    谢谢大家,

    埃里克

    2 回复  |  直到 10 年前
        1
  •  2
  •   Community kfsone    7 年前

    我刚刚发现 this thread on StackOverflow here 以下内容:

    我想这回答了我自己的问题。没有关系。。。

        2
  •  1
  •   malex    11 年前

    起初, 代表们 应该是 弱/赋值 类型。但在这种情况下,有一个非常常见的 由滚动动画驱动的细微障碍。如果使用动画内容偏移更改 你的 滚动视图 你必须设置它 代表 释放内存 方法。

    否则,您将得到以下信息

    [YourViewController respondsToSelector:]: message sent to deallocated instance
    

    最常见的例子是:

    1. _tableView is ivar of YourViewController
    2. _tableView.delegate = self;
    3. - (void)scrollViewDidScroll:(UIScrollView *)scrollView is implemented at YourViewController
    4. at some point you call [_tableView scrollToRowAtIndexPath:indexPath 
       atScrollPosition:UITableViewScrollPositionBottom animated:YES];
       or [_tableView setContentOffset:CGPoint animated:YES]
       and try to close YourViewController
    

    CoreAnimation保留了表视图,但您的视图控制器已解除分配!