Does the exception reject the controller instance rejectViewerControllerAnimated

For my application, I want to have several different instances of the same view controller. At the moment I am just creating a new instance, for example:

iSafeViewController *tab = [[iSafeViewController alloc] init];

[tab setModalPresentationStyle:UIModalPresentationFullScreen];
[tab setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

[self presentViewController:tab animated:YES completion:nil];

      

Great. And since this is still done in the iSafeViewController class, I have another button that currently just fires the last controller on the stack.

 - (IBAction)closeTab:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
 }

      

Ok, however, I really want to be able to revert to these instances. So, I have two questions.

  • Whether this instance of the controller removes from memory dismissViewControllerAnimated

    . If not, there is a way I can resubmit it.

  • There is probably a better way to navigate through viewController instances, then presentViewControllerAnimated

    . At least there is a better way to create new instances of a single viewController and be able to navigate through each one, hopefully not on the stack. In other words, if there are three viewController instances, is there a way to go from the third to the main one?

Any ideas would be appreciated. Thank.

+3


source to share


1 answer


β€œDoes this controller instance remove from memory? dismissViewControllerAnimated

If not, is there a way to reimpose it.

The call dismissViewControllerAnimated

does not explicitly remove the view controller from memory, but if no other part of the code stores a strong reference to the view controller, once the view controller rejects your VC, it can be deallocated according to the normal memory management system.

So, if you guarantee that something in your code has a reference to your view controller (other than the VC, which presents it modally), it won't disappear after firing, and yes, that means you can reuse it.

Regarding "random access" to view controllers: you can use UINavigationController

and use type methods popToViewController:animated:

and multiple calls pushViewController:animated:

(no animation!) To create the effect by moving to arbitrary controllers. It looks like a hack.



Alternatively, and preferably, you can write your own custom container controller . It is a view controller that handles the presentation of other view controllers. See Apple Docs .

Here's a good WWDC video on the topic: Implementing UIViewController Containment

Further reading:

+5


source







All Articles