问题
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;
}
回答1:
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.
回答2:
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://stackoverflow.com/a/18892358/1378447
N.B. It is still a mystery to me why 'scrollViewDidScroll' delegate method is being called even after dealloc.
回答3:
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
来源:https://stackoverflow.com/questions/18778691/crash-on-exc-breakpoint-scroll-view