presentModalViewController viewDidLoad not being called
I have an event which calls a view to appear, but the -viewdidload
event isn't appearing as expected each time it's called. Here's the method I use to call it...
[self presentModalViewController:addItemViewController animated:YES];
then inside the addItemViewController, the method is
- (void)viewDidLoad {
NSLog(@"alright, lad!");
}
To close the view, I have a button with the code
- (IBAction)cancel {
[self dismissModalViewControllerAnimated:YES];
}
the "alright, lad" log is shown the 开发者_JS百科first time the view appears, but never again when it's launched. Is there a method I can use to let the app "forget" about the view? Or should I be using another load method? I tried loadView (I think) but that had a blank screen...
Thanks for any help!
viewDidLoad is only called when the view is first instantiated. If you're not recreating the view controller each time, you'll only get it called once (and called again if you get a memory warning, and the view is nil'd out). You probably want to use viewWillAppear: or viewDidAppear:.
Make sure you call the superclass in each of those methods, e.g.
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"view appeared");
[super viewWillAppear:animated];
}
精彩评论