Referencing a view controller object from the AppDelegate

Discussion in 'iOS Programming' started by RossOliver, Aug 12, 2008.

  1. RossOliver macrumors regular

    Joined:
    Nov 6, 2006
    #1
    Hey,

    I have my AppDelegate, which on start up runs my MainWindow.xib creating a mainWindowViewController. That view controller goes on to present a modal view controller, which has an instance variable I need to access upon the termination of my application (to save state). How on earth do I go about referencing this object?

    Cheers,

    -Ross
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Why not just save the state when that variable is changed, inside its class?
     
  3. RossOliver thread starter macrumors regular

    Joined:
    Nov 6, 2006
    #3
    Since only the AppDelegate receives the appDidTerminate (can't remember the exact method name) message it needs to call the object to inform it to save state. I managed to do this by just linking an instance variable to the view controller in AppDelegate then I got it's modalViewController, checked it to make sure the class name was correct and then I could access the property I needed...

    -Ross
     

Share This Page