0

我正在使用 ARC 并在 iOS7 (iPhone 5S) 上进行测试。

我有一个带有推送 UIViewController (b) 的导航控制器 (a)。b 通过手动 segue 呈现模态 NavigationViewController (c)。c 然后推送一个 UIViewController (d)。

所以现在我们有 2 个导航堆栈,一个根和一个模态。

每当我进入后台时,我都想关闭模态 NavigationViewController (c) 及其所有子项。

在 UIViewController (b) 我有以下代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(enteredBackground:)
                                             name:UIApplicationDidEnterBackgroundNotification object:nil];

}
-(void)enteredBackground:(NSNotification *)notification{
    if (self.presentedViewController) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

如果我在进入后台时在 C 的 rootViewController 上,这可以正常工作,但在我在 D 上时会崩溃。

2013-10-20 22:49:49.008 MyApp[2596:60b] *** -[UIView release]: message sent to deallocated instance 0x17036aa40

我该如何解决?似乎正在发送模式导航堆栈中的视图dealloc并且已经发布。在调试器中查看后,模态 nvaigationcontroller (c) 本身似乎仍然存在。

4

1 回答 1

0

我制作了一个测试样本并检查了相同的场景,它不会在任何地方崩溃。请检查您的 ViewController C 和 D 中有关 UIView 类型对象的任何版本。或者您可以将代码发布到您正在执行上述所有内容的地方。

于 2013-10-21T09:48:40.093 回答