Note that there are some explanatory texts on larger screens.

plurals
  1. POXCode: insertSubview, removeFromSuperview, viewDidLoad... Pulling it all together
    primarykey
    data
    text
    <p>I feel like I'm missing something basic here, and I would appreciate it if you'd help me pull it all together.</p> <p>Let's say that I have two view controllers... ViewAController and ViewBController.</p> <p>If I wanted to show viewA, I would do this:</p> <pre><code>ViewAController *new_view = [[ViewAController alloc] initWithNibName:@"ViewAController" bundle:nil]; self.viewAController = new_view; [self.view insertSubView:new_view.view atIndex:0]; [new_view release]; </code></pre> <p>If, after showing viewA, I wanted to show viewB controller, I would do this:</p> <pre><code>[self.viewAController.view removeFromSuperview]; ViewBController *new_view = [[ViewBController alloc] initWithNibName:@"ViewBController" bundle:nil]; self.viewBController = new_view; [self.view insertSubView:new_view.view atIndex:0]; [new_view release]; </code></pre> <p>Here is my question...</p> <p>When I load viewA for the first time, viewA's "viewDidLoad" function fires off... It's obviously being loaded for the first time. However, when I remove viewA from the superview, load in viewB, and then later on load viewA again like this:</p> <pre><code>[self.viewBController.view removeFromSuperview]; if ( self.viewAController == nil ) { ViewAController *new_view = [[ViewAController alloc] initWithNibName:@"ViewAController" bundle:nil]; self.viewAController = new_view; [self.view insertSubview:new_view.view atIndex:0]; [new_view release]; } else { [self.view insertSubview:self.viewAController.view atIndex:0]; } </code></pre> <p>viewA's "viewDidLoad" function does NOT fire off. It's as though viewA has been removed from the view, but it's state is sort of saved in memory. When I load viewA again, it just sort of picks up from where it left off. What I really need it to do is load up as though it's loading for the first time again, with "viewDidLoad", etc...</p> <p>I hope I have explained this properly. If anyone could provide some enlightenment, I would appreciate it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload