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?

有帮助吗?

解决方案 2

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;
}

其他提示

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
}

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top