3

It is a bit tricky to explain, but I will try. When I navigate backwards from the "Mercurial page" (see picture) when the scrollview is scrolled, my app crashes. But when it is not scrolled, the app does not crash... I have implemented <UIScrollViewDelegate> Any help would be greatly appreciated! Here are some pictures and some code that I have in my app:

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [self.scrollView layoutIfNeeded];
    self.scrollView.contentSize=self.contentView.bounds.size;
}

- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat yPos = -scrollView.contentOffset.y;
    if (yPos > 0) {

        CGRect imgRect = self.imageView.frame;
        imgRect.origin.y = scrollView.contentOffset.y;
        imgRect.size.height = HeaderHeight+yPos;
        self.imageView.frame = imgRect;
}

enter image description here

enter image description here

enter image description here

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
b3rge
  • 4,959
  • 7
  • 23
  • 24
  • 1
    You should catch *All Exceptions* in Xcode. – Lorenzo B Jan 04 '14 at 16:43
  • 1
    Can you please add an exception breakpoint to your project and run the app again. With that you will identify the exact code line that causes the crash. – Florian Mielke Jan 04 '14 at 16:43
  • http://stackoverflow.com/questions/4961770/run-stop-on-objective-c-exception-in-xcode-4 – Lorenzo B Jan 04 '14 at 16:43
  • Yeah I'd say add an exception breakpoint as well as a breakpoint in the scrollViewDidScroll method. I assume something is happening there when you hit back....maybe it's trying to scroll up before navigating back and there's issues as the view is unwound. – valheru Jan 04 '14 at 16:59
  • 3
    One most common cause for `UIScrollViewDelegate` related app crashes is, well, the delegate. I would suggest you to set the scrollView delegate to `nil` in `viewWillDisappear`. If you push other view controllers from this view controller, use `if([self isMovingFromParentViewController])`. Try doing this. If the problem persists, we'll delve deeper. – n00bProgrammer Jan 04 '14 at 17:48
  • Yeah, setting scrollView.delegate = nil; in the viewWillDisappear solved the problem, thank you so much @n00bProgrammer ! – b3rge Jan 04 '14 at 23:46
  • 1
    @n00bProgrammer That was it! Please, have all my internet points for today! Why don't you turn your comment into an answer so we can upvote you into heaven! – shezi Apr 25 '14 at 13:20
  • This is not actually a *solution*. The real solution would be to find the code that causes the crash, in the scroll view delegate methods. This merely helps recognise whether it's the delegate responsible, or not. One possible solution would be to use a `BOOL` like `_viewIsActive` that you toggle in `viewDidAppear` and `viewWillDisappear`, and check it's state in your delegate methods before executing relevant code. – n00bProgrammer Apr 26 '14 at 06:08

1 Answers1

6

this worked for me.

-(void)viewWillDisappear:(BOOL)animated{
    [self.scrollView setDelegate:nil];
}
Paresh Dudhat
  • 1,166
  • 1
  • 14
  • 28