Crash on EXC_Breakpoint Scroll View
Asked Answered
C

3

13

This is a new problem I have been having ever since I've been updating my app for iOS 7. Everytime I launch the app on my device or simulator, I get this error code

RecipeDetailViewController scrollViewDidScroll:]: message sent to deallocated instance 0x15746c40 and it crashed.

I enabled NSZombie and that was the code it gave me. Before it was giving a exc_bad_access code.

This is my code for ScrollViewDidSCroll

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{


    // Depending on how far the user scrolled, set the new offset.
    // Divide by a hundred so we have a sane value. You could adjust this
    // for different effects.
    // The larger you number divide by, the slower the shadow will change

    float shadowOffset = (scrollView.contentOffset.y/1);

    // Make sure that the offset doesn't exceed 3 or drop below 0.5
    shadowOffset = MIN(MAX(shadowOffset, 0), 0.6);

    //Ensure that the shadow radius is between 1 and 3
    float shadowRadius = MIN(MAX(shadowOffset, 0), 0.6);



    //apply the offset and radius
    self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(0, shadowOffset);
    self.navigationController.navigationBar.layer.shadowRadius = shadowRadius;
    self.navigationController.navigationBar.layer.shadowColor = [UIColor blackColor].CGColor;
    self.navigationController.navigationBar.layer.shadowOpacity = 0.2;
}
Cloth answered 13/9, 2013 at 5:7 Comment(0)
M
23

Another (inelegant, imo) solution is to set your table's delegate to nil on dealloc:

- (void)dealloc {
    [_tableView setDelegate:nil];
}

Seems to be a bug, but I can't guarantee. I am still looking for a reasonable explanation for that.

Note: that probably applies for any UIScrollView subclass, not only UITableView.

Mumbletypeg answered 25/9, 2013 at 17:52 Comment(1)
This is absolutely the correct answer!!! I discovered that setting the delegate=nil was the solution, but tried to put it in viewWill/DidDissappear and in other tons of places... this saved my day!Felicidadfelicie
F
7

I was facing the exact situation. I enabled NSZombie, gave me the exact same error in ios7.

In viewDidLoad

[self setEdgesForExtendedLayout:UIRectEdgeNone];

Solved my crash. You can also try from storyboard unselect the Extended Edges >> Under top bars.

see the answer here https://mcmap.net/q/903935/-uiview-under-uinavigationbar-on-ios7

N.B. It is still a mystery to me why 'scrollViewDidScroll' delegate method is being called even after dealloc.

Furriery answered 19/9, 2013 at 11:35 Comment(0)
T
1

or if you watching for table view scrolling

- (void)viewWillDisappear:(BOOL)animated
{
    _table.delegate = nil;
}

Anyway its strange to call notification or something like that on dealloc enter image description here

Tailpipe answered 28/10, 2014 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.