开发者

remove ViewController from memory

开发者 https://www.devze.com 2022-12-27 09:52 出处:网络
I hope to load an ViewController and do something then unload (viewDidUnload) it from memory. if (self.vViewController5.view.superview==nil)

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


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).


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

0

精彩评论

暂无评论...
验证码 换一张
取 消