I have this view controller with a paged UIScrollView. Specifically this scroll view has 3 pages, and I want it to start at the second page. So when the view loads I adjust the content offset to start at the second page:
CGFloat offsetX = _pageWidth * SECOND_PAGE;
[_scrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
But when I hit the "Back" button in the UINavigationBar, and the UIScrollView is not in the second page, the error occurs.
The stack trace shows that the navigation controller removes the view, deallocs, calls in the scroll view the method removeFromSuperview
, and after this the UIScrollView calls adjustContentoffsetIfNeccesary--->notifyDidScroll
. So I think that what's happening is that the UIScrollView wants to notify the UIScrollView delegate that a scroll has occurred, but the delegate has already been releases, and the EXC_BAD_ACCESS
occurs.
So, anyone knows what's the correct way of achieving the behaviour I want?
Here's the stack trace I talked about:
#1 0x0075595b in -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] ()
#2 0x0073fc43 in -[UIScrollView setContentOffset:] ()
#3 0x0075ccae in -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] ()
#4 0x00758b46 in -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] ()
#5 0x00758bda in -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] ()
#6 0x0074069e in -[UIScrollView removeFromSuperview] ()
#7 0x0071a715 in -[UIView dealloc] ()
#8 0x00718124 in -[UIView release] ()
Thanks.