EXC_Breakpoint滚动视图崩溃

时间:2013-09-13 05:07:55

标签: 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;
}

3 个答案:

答案 0 :(得分:22)

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

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

似乎是一个错误,但我无法保证。我仍然在寻找合理的解释。

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

答案 1 :(得分:7)

我正面临着确切的情况。我启用了NSZombie,在ios7中给了我完全相同的错误。

viewDidLoad

[self setEdgesForExtendedLayout:UIRectEdgeNone];

解决了我的崩溃。您也可以在故事板中尝试取消选择Extended Edges>> Under top bars

在此处查看答案https://stackoverflow.com/a/18892358/1378447

N.B。对我来说,为什么即使在dealloc之后调用'scrollViewDidScroll'委托方法仍然是个谜。

答案 2 :(得分:1)

或者如果你正在观看桌面视图滚动

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

无论如何,在dealloc上调用通知或类似的东西很奇怪 enter image description here

相关问题