viewDidUnload和didReceiveMemoryWarning兼容性
viewDidUnload不允许在ios6上,所以如何兼容性viewDidUnload和didReceiveMemoryWarning来调用。 我需要viewDidUnload和didReceiveMemoryWarning兼容性
- (void)viewDidUnload{
self.listArr=nil;
[super viewDidUnload];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
float sysVer =[[[UIDevice currentDevice] systemVersion] floatValue];
if (sysVer>= 6.0f){
if([self isViewLoaded] && !self.view.window){
self.listArr=nil;
self.view = nil;
}
}
NSLog(@" BrowseComment didReceiveMemoryWarning");
}
或仅在iOS5的使用后续的代码和iOS6的
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
if([self isViewLoaded] && !self.view.window){
self.listArr=nil;
self.view = nil;
}
NSLog(@" BrowseComment didReceiveMemoryWarning");
}
在iOS 6中,所述viewWillUnload和viewDidUnload UI的方法ViewController现在已被弃用。如果您使用这些方法发布数据,请改用didReceiveMemoryWarning方法。如果未使用视图控制器视图,也可以使用此方法释放对视图控制器视图的引用。
当前在viewDidUnload
中使用的代码应该被转换为didReceiveMemoryWarning
。它同时适用于iOS5 & iOS6。实际上,在此更改发生之前,只有在应用程序确实收到内存警告时,才会调用viewDidUnload
方法。所以viewDidUnload
没有什么特别的意义。所以他们弃用它。
如何在iOS5的发布数据和iOS6的 – pengwang 2013-02-19 11:43:36
您可以使用didReceiveMemoryWarning在这两种情况下..如果使用ios5,请参阅编辑 – 2013-02-19 11:52:15
从iOS 6开始,viewDidUnload
和viewWillUnload
没有任何作用。
所以,如果你需要处理的内存警告,这样做在didReceiveMemoryWarning
,我可以在didReceiveMemoryWarning中执行它 – pengwang 2013-02-19 11:49:31
@peng wang:确定你可以在iOS 5中做到这一点。 – 2013-02-19 14:14:54
请参阅本[http://*.com/questions/12674268/ios-6-viewdidunload-migrate-to-didreceivememorywarning ] [1] [1]:http://*.com/questions/12674268/ios-6-viewdidunload-migrate-to-didreceivememorywarning – 2013-02-19 11:44:24