开发者

How to determine if UIScrollView crash is in my code or Apple's? [duplicate]

开发者 https://www.devze.com 2022-12-21 07:42 出处:网络
This question already has answers here: Is there a way to cancel an animated UITableView/UIScrollView setContentOffset:animated:?
This question already has answers here: Is there a way to cancel an animated UITableView/UIScrollView setContentOffset:animated:? (3 answers) Closed 3 years ago.

I periodically am reproing a crash on a debug build running on my iPhone involving a UIScrollView with none of my code in the stack frame. I would like to know if it's a bug in my code or Apple's, and I am unable to query the Apple bug database to see if it has been reported. The backtrace shows:

#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

The problem is apparently in UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded. GDB reports:

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

In MyViewController, I do have a call to scroll a tableView:

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

Because it's animated, it's clearly possible that the view could get popped off the navigation controller before the scrolling animation completes. It seems like it should be the job of the UIView to cancel or wait for any pending scrolling operations when it is unloading. Therefore, I think this is a bug in Apple's code.

Or am I mistaken, and is there some kind of checking my view must do check if it's scrolling prior to unloading, or am I misreading this crash entirely?

FYI, this bug also only appears to repro in low-memory conditions, i.e. I have started receiving didRe开发者_C百科ceiveMemoryWarning callbacks.

Thanks all,

Eric


At first, delegates should be of weak/assign type. But event in this case there is a very common subtle obstacle driven by scroll animations. If you use animated content offset changes for your ScrollViews you strongly need to set its delegate to nil at dealloc method.

Otherwise you will get the following

[YourViewController respondsToSelector:]: message sent to deallocated instance

The very common example:

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

The _tableView is retained by CoreAnimation, but YourViewController is deallocated!

0

精彩评论

暂无评论...
验证码 换一张
取 消