viewDidAppear question

Discussion in 'iOS Programming' started by mrl72, Feb 2, 2011.

  1. macrumors regular

    Joined:
    Apr 20, 2008
    #1
    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!
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You sure there's not another method where you could put this, one that gets executed only when the view Did Load (hint, hint)?
     
  3. thread starter macrumors regular

    Joined:
    Apr 20, 2008
    #3
    It's in ViewDidLoad now. Since my method calls a modal window it won't work until the view has appeared.
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Then, yeah, I think in viewDidAppear with a boolean would be a suitable approach (although I suspect there are others).
     
  5. thread starter macrumors regular

    Joined:
    Apr 20, 2008
    #5
    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.
     
  6. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    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.
     

Share This Page