【问题标题】:Message Sent to Deallocated instance when going to background进入后台时发送到 Deallocated 实例的消息
【发布时间】:2013-10-21 02:52:00
【问题描述】:

我正在使用 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) 本身似乎仍然存在。

【问题讨论】:

  • 这一定是您正在关闭的视图控制器中的某些保留/释放代码的问题 - 请在关闭的控制器周围提供更多代码
  • 没有保留/释放代码。我正在使用弧。我也没有在任何这些对象上声明和明确的弱或强属性。
  • ARC 并不意味着没有保留/释放 :) 您仍然必须定义强/弱引用(转换为保留或分配)。如果您不了解保留/释放的基础知识,我建议您在知道如何手动管理之后使用 MRC 并转到 ARC - 这样您就不会犯基本错误。
  • 我明白。我是说因为弧,我没有明确的保留/释放。但我没有对任何观点持有任何强/弱引用,除了故事板所做的引用。
  • @PRNDL Development Studios,您找到解决方案了吗?我在我身边也一样。

标签: iphone objective-c memory-management uiviewcontroller automatic-ref-counting


【解决方案1】:

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

【讨论】:

  • 我可以发帖,但没有明确的发布或保留。我正在使用弧。当我回到我的电脑时,我会发布代码。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-26
  • 2012-10-07
  • 1970-01-01
  • 2012-08-22
  • 2016-08-28
  • 2011-06-16
  • 2013-08-30
相关资源
最近更新 更多