如何确定UIScrollView崩溃是在我的代码还是Apple的?

esi*_*ver 5 iphone uiscrollview

我定期在我的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
Run Code Online (Sandbox Code Playgroud)

问题显然在于UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded.GDB报告:

-[MyViewController respondsToSelector:]: message sent to deallocated instance 0x5d77ad0
Run Code Online (Sandbox Code Playgroud)

在MyViewController中,我确实有一个滚动tableView的调用:

[self.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];  
Run Code Online (Sandbox Code Playgroud)

因为它是动画的,所以在滚动动画完成之前,显然可能会从导航控制器弹出视图.看起来应该是UIView的工作是在卸载时取消或等待任何挂起的滚动操作.因此,我认为这是Apple代码中的一个错误.

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

仅供参考,此错误也仅在低内存条件下出现重现,即我已开始接收didReceiveMemoryWarning回调.

谢谢大家,

埃里克

mal*_*lex 1

首先,委托应该是弱/分配类型。但在这种情况下,存在一个由滚动动画驱动的非常常见的微妙障碍。如果您对ScrollView使用动画内容偏移更改,则强烈需要在dealloc方法中将其委托设置为nil

否则你会得到以下信息

[YourViewController respondsToSelector:]: message sent to deallocated instance
Run Code Online (Sandbox Code Playgroud)

非常常见的例子:

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
Run Code Online (Sandbox Code Playgroud)

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