PDA

View Full Version : viewDidAppear question




mrl72
Feb 2, 2011, 12:24 PM
I have a need to show something to the user as soon as the view has loaded for the first time. So I have a method in viewDidAppear that does this. The problem is whenever I open a modal window in full screen when it returns it always executes viewDidAppear method in the parent controller, which runs my method again. What is the best way to handle this? Is it a simple case of just checking a BOOL value for first time app is loaded, or am I going about this completely the wrong way?

Cheers!



dejo
Feb 2, 2011, 12:27 PM
I have a need to show something to the user as soon as the view has loaded for the first time.
You sure there's not another method where you could put this, one that gets executed only when the view Did Load (hint, hint)?

mrl72
Feb 2, 2011, 12:29 PM
It's in ViewDidLoad now. Since my method calls a modal window it won't work until the view has appeared.

dejo
Feb 2, 2011, 12:31 PM
It's in ViewDidLoad now. Since my method calls a modal window it won't work until the view has appeared.

Then, yeah, I think in viewDidAppear with a boolean would be a suitable approach (although I suspect there are others).

mrl72
Feb 2, 2011, 12:33 PM
OK cool. BTW is it normal for the dismissal of a full screen modal window to call the parent ViewDidAppear method anyway? Notice it doesn't do it on the other modal presentation styles.

Cheers.

PhoneyDeveloper
Feb 2, 2011, 02:06 PM
Yes, it's normal. viewWill/DidAppear are called every time a view controller's view appears or is revealed. That means when the view first appears after being pushed or presented and also if a detail view or modal view that was in front of that view goes away.

See the view controller programming guide.