views:

181

answers:

2

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!

+1  A: 

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
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
neither is getting called ever?
Ben Gottlieb
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
Something is wrong; those methods should get called. You have the following prototypes, right? - (void) viewWillAppear: (BOOL) animated; - (void) viewDidAppear: (BOOL) animated;
Ben Gottlieb
A: 

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

- (void)viewWillAppear:(BOOL)animated {
  NSLog(@"view appeared");
  [super viewWillAppear:animated];
}
imnk
what does this actually do? (calling the superclass?)
Matt Facer
For most of these, it's doc'd to do nothing. You should still call it, however, as that may change in the future.
Ben Gottlieb