What happens to views in navigation controller

Discussion in 'iOS Programming' started by beardedpig, Jan 19, 2009.

  1. beardedpig macrumors member

    Dec 17, 2008
    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. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    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. beardedpig thread starter macrumors member

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

    -(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. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Perhaps try moving the "imageView.image = image;" into viewDidLoad.

Share This Page