uiscrollview - EXC_Breakpoint ScrollView 崩溃

标签 uiscrollview dealloc

这是我为 iOS 7 更新应用程序以来一直遇到的一个新问题。每次在设备或模拟器上启动应用程序时,我都会收到此错误代码

RecipeDetailViewController scrollViewDidScroll:]: 消息发送到释放的实例 0x15746c40 并且它崩溃了。

我启用了 NSZombie,这就是它给我的代码。在它给出 exc_bad_access 代码之前。

这是我的 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;
}

最佳答案

另一个(不优雅,imo)解决方案是在 dealloc 上将表的委托(delegate)设置为 nil:

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

似乎是一个错误,但我不能保证。我仍在为此寻找合理的解释。

注意:这可能适用于任何 UIScrollView 子类,而不仅仅是 UITableView。

关于uiscrollview - EXC_Breakpoint ScrollView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18778691/

相关文章:

iphone - ViewController 永远不会被释放

ios - TableView Cell 视频自动播放

ios - ScrollViewDelegate 不调用 scrollViewDidScroll 或 scrollViewWillBeginDragging

ios - UIScrollView 总是跳回顶部

ios - UIScrollView 与 UIView (Swift)

ios - UIScrollView 不滚动?

objective-c - iOS 中的 Dealloc 方法并将对象设置为 nil

ios dealloc 与 autoreleasepool

c++ - Qt:写这个类的析构函数的正确和安全的方法是什么?

ios - didReceiveMemoryWarning 和 dealloc 之间有什么关系?