0

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!

Matt Long
  • 24,438
  • 4
  • 73
  • 99
Matt Facer
  • 3,103
  • 11
  • 49
  • 91

2 Answers2

2

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

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
  • I have tried both methods and neither do anything. I might just have to look at a different way to call the view up. – Matt Facer Dec 22 '09 at 12:02
  • neither is getting called ever? – Ben Gottlieb Dec 22 '09 at 13:08
  • nope. I put in all three events with an output to the log and only the viewdidload appeared the first time, then nothing did. Tried them separately too, no joy. I've done a work around and have called the function which was on the view from my delegate file. C'est la vie! Thanks for the help anyway :) – Matt Facer Dec 22 '09 at 13:51
  • Something is wrong; those methods should get called. You have the following prototypes, right? - (void) viewWillAppear: (BOOL) animated; - (void) viewDidAppear: (BOOL) animated; – Ben Gottlieb Dec 22 '09 at 14:59
0

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

- (void)viewWillAppear:(BOOL)animated {
  NSLog(@"view appeared");
  [super viewWillAppear:animated];
}
imnk
  • 4,342
  • 3
  • 29
  • 31