尝试关闭iOS中的弹出窗口时出现异常

时间:2014-04-14 03:54:20

标签: ios debugging exception crash

抱歉,我已经缩小了这个bug,因此它不是AFNetworking问题,而是UI问题。

我有一个集合视图。当我点击集合视图时,会显示一个弹出窗口,我可以选择下载某个东西,然后进度条会显示进度。同时,collectionviewcell还会在其自身上显示另一个进度条。然后我关上窗户再次敲击细胞,做一些事情然后关闭它。它可能不会在第二次引发异常,当我再次打开和关闭popOver时,会引发异常。

这是来自lldb的bt追踪:

* thread #1: tid = 0x1214fc, 0x38592626 libobjc.A.dylib`objc_msgSend + 6, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xb1b8d8b0)
    frame #0: 0x38592626 libobjc.A.dylib`objc_msgSend + 6
    frame #1: 0x302f7056 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 90
    frame #2: 0x302f6ff6 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
    frame #3: 0x302f6fd0 UIKit`-[UIControl sendAction:to:forEvent:] + 44
    frame #4: 0x302e2736 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 374
    frame #5: 0x302f6a4e UIKit`-[UIControl touchesEnded:withEvent:] + 590
    frame #6: 0x302f6720 UIKit`-[UIWindow _sendTouchesForEvent:] + 528
    frame #7: 0x302f16ea UIKit`-[UIWindow sendEvent:] + 758
    frame #8: 0x302c68ec UIKit`-[UIApplication sendEvent:] + 196
    frame #9: 0x302c4f96 UIKit`_UIApplicationHandleEventQueue + 7102
    frame #10: 0x2da7125a CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
    frame #11: 0x2da7072a CoreFoundation`__CFRunLoopDoSources0 + 206
    frame #12: 0x2da6ef1e CoreFoundation`__CFRunLoopRun + 622
    frame #13: 0x2d9d9f4e CoreFoundation`CFRunLoopRunSpecific + 522
    frame #14: 0x2d9d9d32 CoreFoundation`CFRunLoopRunInMode + 106
    frame #15: 0x328d3662 GraphicsServices`GSEventRunModal + 138
    frame #16: 0x3032516c UIKit`UIApplicationMain + 1136
  * frame #17: 0x0003b12c ChinesePod`main(argc=1, argv=0x27dccd04) + 300 at main.m:39

通过查看跟踪,我不知道出了什么问题。知道我的应用程序有什么问题吗?

编辑:

当我启用NSZombie时,我在控制台中看到了这个错误:

*** -[BlurViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x166e7df0

BlurViewController是一个viewcontroller,负责显示PopOver窗口。这是否意味着释放了BlurViewController?

dismissDialog的源代码:

- (void)dismissDialog
{
    [UIView animateWithDuration:kAnimationDuration animations:^{
        self.view.alpha = 0.f;
        self.popUp.transform = CGAffineTransformMakeScale(0, 0);
    } completion:^(BOOL finished) {
        [self removeFromParentViewController];
        [self.view removeFromSuperview];
        [self.popUp removeFromSuperview];
        if (!self.popUp.isDownloading) {
            _popUp = nil;
        }

        [UIView animateWithDuration:kAnimationDuration animations:^{
            _blurView.alpha = 0.f;
        } completion:^(BOOL finished) {
            [_blurView removeFromSuperview];
        }];
    }];
}

1 个答案:

答案 0 :(得分:0)

经过一天的调试后,我终于解决了。

之前我在我的主viewController中定义了一个BlurViewController实例bvController作为方法变量,但似乎在我关闭popOver UIView后发布了bvController。我将bvController移到了一个强大的属性,并在该方法中使用以下代码,该应用程序不再崩溃。

MainViewController.h:

@property (strong, nonatomic)  BlurViewController *bvController;

MainViewController.m:

if (!self.bvController) {
    self.bvController = [[BlurViewController alloc] init];
}

内存分配和解除分配在Objective-C中非常有用。来自Java和Python背景,我总是在这里和那里摸不着头脑。