views:

93

answers:

2

hello everyone

I hope to load an ViewController and do something then unload (viewDidUnload) it from memory.

 if (self.vViewController5.view.superview==nil)
 {

  ViewController5 *blueController = 
  [[ViewController5 alloc] initWithNibName:@"View5" bundle:nil];

  self.vViewController5 = blueController;

  [self.vViewController5 setDelegate:self];
  [blueController release];
 }



 [self presentModalViewController:vViewController5 animated:YES]; 

later, call

 [self dismissModalViewControllerAnimated:YES];

but I found that dismissModalViewControllerAnimated does not trigger the event viewDidUnload of Viewcontroller5.

I try function release but it caused program collapse. I also try removeFromSuperView but it does not trigger the event ViewDidUnload neither.

Welcome any comment

Thanks

interdev

A: 

A dismissed UIViewController will not trigger the viewDidUnload, as you have discovered. However it will trigger viewWillDisappear method, if that suit your needs.

Björn
+1  A: 

viewDidUnload is only called when your application receives a memory warning, and the view is not active. It's generally used for releasing retained views (including IBOutlets). You can use viewWillDisappear or viewDidDisappear to respond to a dismissal (dealloc will also be called eventually, but not necessarily exactly when the view is dismissed).

eman
Is there a way to unload viewcontroller from memory?
When you dismiss a modal view controller, it will be released and usually deallocated (unless you've retained it somewhere).
eman