繁体   English   中英

在转换为ARC时,我们将-dealloc中的代码放在哪里?

[英]Where do we put code that was in -dealloc when converting to ARC?

我在dealloc中有一个带有此方法调用的类:

- (void)dealloc {

    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

将类转换为ARC后,我将自己从通知中心移除? 它应该在viewDidUnload中吗? 该通知用于侦听来自模态视图控制器的事件,因此我无法将此代码放入viewWillDisappear中。

dealloc保留在ARC中,只是你不应该再调用[super dealloc] :编译器会为你插入代码。 当然,所有release的调用都不能在dealloc (或其他任何地方)中进行。

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    // [super dealloc]; <<== Compiler inserts this for you
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM