Matt Facer
Matt Facer

Reputation: 3105

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 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!

Upvotes: 0

Views: 2169

Answers (2)

imnk
imnk

Reputation: 4372

Make sure you call the superclass in each of those methods, e.g.

- (void)viewWillAppear:(BOOL)animated {
  NSLog(@"view appeared");
  [super viewWillAppear:animated];
}

Upvotes: 0

Ben Gottlieb
Ben Gottlieb

Reputation: 85532

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

Upvotes: 2

Related Questions