【问题标题】:How to determine if UIScrollView crash is in my code or Apple's? [duplicate]如何确定 UIScrollView 崩溃是在我的代码中还是在 Apple 的代码中? [复制]
【发布时间】:2014-09-29 09:29:26
【问题描述】:

我会定期在我的 iPhone 上运行的调试版本中重现崩溃,该版本涉及 UIScrollView,而堆栈帧中没有我的代码。我想知道这是我的代码中的错误还是 Apple 的错误,并且我无法查询 Apple 错误数据库以查看它是否已被报告。回溯显示:

#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 的工作。因此,我认为这是苹果代码中的一个错误。

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

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

谢谢大家,

埃里克

【问题讨论】:

    标签: iphone uiscrollview


    【解决方案1】:

    首先,delegates 应该是 weak/assign 类型。但是在这种情况下,有一个非常常见的事件 滚动动画驱动的微妙障碍。如果您使用动画内容偏移更改 您的 ScrollViews 您强烈需要在 dealloc 方法中将其 delegate 设置为 nil

    否则你会得到以下结果

    [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
    

    _tableView 被 CoreAnimation 保留,但 YourViewController 被释放!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多