What happens to views in navigation controller

Discussion in 'iPhone/iPad Programming' started by beardedpig, Jan 19, 2009.

  1. macrumors member

    Joined:
    Dec 17, 2008
    #1
    Does anyone know what happens to a viewcontroller that is moved to the left as a new view is pushed onto the stack?

    For example if the viewcontroller is pushed onto the stack and whilst in display is modified. Then another view is pushed onto the stack and scrolls in from the right.

    When this final view is popped off the stack resulting in the previous view coming back into view should this returning view still retain the modified state and not the state it was originally in when pushed on the stack?
     
  2. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    It depends.

    In most cases the view controller that is hidden and then revealed doesn't change at all.

    However, in the case of a memory warning a hidden view controller will have its view unloaded and then reloaded. After the view is reloaded the view controller will appear to have reverted to a previous state, unless things are coded specifically to work around this.

    Also, when the view controller reappears its viewWillAppear and viewDidAppear methods are called. Depending on how they're written the view may be updated with new data. For example if you have a table that pushes a detail view that allows the user to edit something then when the detail view is popped the table should update itself with the new values.
     
  3. thread starter macrumors member

    Joined:
    Dec 17, 2008
    #3
    HI, really appreciate your answer thanks and in digesting it I looked at this bit of code in my app:

    Code:
    -(void) viewWillAppear: (BOOL) animated
    {	
    	imageView.image = image;
    	
    	[super viewWillAppear: animated];
    }
    
    Now I am trying to find the book and section which said you should do this, but when I commented it out the app runs exactly as I want it to, i.e not reverting to the initialising image!
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Perhaps try moving the "imageView.image = image;" into viewDidLoad.
     

Share This Page