Valerii  Pavlov
Valerii Pavlov

Reputation: 2033

viewDidUnload not called for alloc/init initialized viewcontroller with no xib file

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?

Upvotes: 0

Views: 1045

Answers (3)

Rob
Rob

Reputation: 437552

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.

Upvotes: 0

Valerii  Pavlov
Valerii Pavlov

Reputation: 2033

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

Upvotes: 0

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

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
}

Upvotes: 0

Related Questions