Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're using ARC, you don't need to worry about releasing the existing view controller; the compiler will do it for you. If you aren't using ARC, but you are using synthesized properties, then the compiler will still handle the memory management for you. If you write your own accessor methods and are not using ARC, just ensure that the your accessor methods obey the memory management rules of accessor methods. If you aren't using your accessor methods, then release the old ivar before overwriting it with the new value.</p> <p>Edited: As far as replacing a view controller, you need to carefully distinguish between the view controller and its view.</p> <p>The view controller doesn't need to be reloaded, although that's fine. But the same object which originally loaded it should also be the object that reloads it. Always think in terms of objects, responsibility, and relationships (object ownership).</p> <p>Usually you do something like this:</p> <pre><code>- (void)resetCurrentViewController { UIViewController *old = self.currentViewController; UIView *oldView = old.view UIView *superview = [oldView superview]; UIViewController *new = [[MyViewController alloc] initWithNibName:nil bundle:nil]; UIView *newView = new.view; [UIView transitionWithView:superview duration:0.2 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{ [oldView removeFromSuperview]; [containerView addSubview:newView]; } completion:^{ self.currentViewController = new; }]; } </code></pre> <p>This is written in the edit box, not from real code, using stand-in variable names. The basics is that "self" (whatever that is) "owns" the "currentViewController", and replaces the current copy with a new copy, while at the same time swapping the old view for the new one, which one assumes will have the new values.</p> <p>But as another commenter said, this seems like overkill. You could alternately reset all the values in the view controller (implement a -reset method in the view controller to do that) and the view (including any text fields or other controls), wrapping the view updates in an animation so you get a nice fade. But there are lots of different ways to do it.</p>
 

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