viewDidUnload no longer called in ios6

时光毁灭记忆、已成空白 提交于 2019-12-03 05:46:23

问题


I just installed the new version of Xcode/ios6. viewDidUnload is now depreciated.

In the apple doc,

viewDidUnload [...] Deprecated in iOS 6.0. Views are no longer purged under low-memory conditions and so this method is never called.

But numbers of apps are using this callback to release their properties, like :

- (void)viewDidUnload {
    [super viewDidUnload];

    self.recipientButton = nil;
    self.connectButton = nil;
    self.infoLabel = nil;
}

This was the best practice to release your IBOutlets.

So, first question:
What is going to happen these existing apps in iOS 6? Will they leak ?

and second one:
What is the new recommended way to release an IBOutlet property ? In dealloc method ?


回答1:


For the first Question:

Your ViewController will receive didReceiveMemoryWarning method callback and you can nil out the view & other components in this method

For Reference Do Check WWDC 2012 video Session on EVOLUTION OF VIEW CONTROLLER, in case you haven't (I Believe they are available only for registered developers, but not sure).

Answer to your second one.

[object release]; in dealloc. No need to assign nil to object before releasing.




回答2:


I recommend you to use weak property for the IBOutlets like

@property (weak) IBOutlet UILabel * labelText;

That way you don't need to do anything in dealloc. In iOS 6, simply ViewDidUnload won't call, iOS5 or earlier it is just call when memory warning have occur.




回答3:


and second one: What is the new recommended way to release an IBOutlet property ? In dealloc method ?

What is the "old" recommended way? You must always release retained instance variables in dealloc; it has always been this way and continues to be this way.

It was just that in viewDidUnload (which is only called for low memory) you could also set your properties to nil.



来源:https://stackoverflow.com/questions/12509102/viewdidunload-no-longer-called-in-ios6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!