viewDidUnload not called for alloc/init initialize

2019-06-13 19:58发布

Why isn't viewDidUnload method called, when I'm not using xib and use alloc/init to initialize my ViewController when i simulate memory warning for any iOS version via Simulator? It seems as if this method is never called.

If I create controller via alloc/initWithNibName with xib file, viewDidUnload method successfully called. Why does it happend? Does xib file is reqired for all viewcontrollers to normal handling of memory warnings?

3条回答
劳资没心,怎么记你
2楼-- · 2019-06-13 20:19

I solve my problem. My implementation with no xib just need to add this code:

- (void) loadView {
   UIView * myView = [[[UIView alloc] init] autorelease];
   self.view = myView;
}
查看更多
霸刀☆藐视天下
3楼-- · 2019-06-13 20:20

Constrained by the terms of the beta program, I believe that we're precluded from being able to discuss iOS 6 Beta in any detail, but I might also suggest that you review the bottom of page 6 in the 8 page iOS 6 Beta 1 release notes regarding viewWillUnload and viewDidUnLoad.

查看更多
看我几分像从前
4楼-- · 2019-06-13 20:29

viewDidUnload is called whenever a memory warning is received and its called for each view controller that has a non visible view, such as a UINavigationController if you push a new view controller and this view controller causes memory shortage the presenting view controller viewDidUnload will be called (because its view is not visible)

Also note that if you implement didReceiveMemoryWarning and do not call [super didReceiveMemoryWarning];, your viewDidUnload does not get called

For example if you have in your view controller this

- (void)didReceiveMemoryWarning
{
    //with 
    [super didReceiveMemoryWarning]; // viewDidUnload gets called

    //without [super didReceiveMemoryWarning]; viewDidUnload does not get called
}
查看更多
登录 后发表回答