VansFannel
VansFannel

Reputation: 46041

Dismiss UIViewController after presenting another one

I'm developing a single view iOS 5.0+ app and I'm going to navigate throw my ViewControllers this way:

SearchViewController* search =
[[SearchViewController alloc] initWithNibName:@"SearchViewController"
                                       bundle:nil];
[self presentViewController:search
                   animated:NO
                 completion:nil];

My question is, if I'm opening SearchViewController from HomeViewController, is HomeViewController dismissed after SearchViewController is shown?

I have a lot of UIViewControllers and I don't know if all of them will be on memory while user is navigating between them.

Upvotes: 2

Views: 247

Answers (2)

Toseef Khilji
Toseef Khilji

Reputation: 17439

If You want to Present Only one Viewcontroller you can try like,

 SearchViewController* search =
    [[SearchViewController alloc] initWithNibName:@"SearchViewController"
                                           bundle:nil];


    [self dismissViewControllerAnimated:NO completion:^{
        [self presentViewController:search
                           animated:NO
                         completion:nil];
    }];

Upvotes: 2

Puneet Sharma
Puneet Sharma

Reputation: 9484

When you present a ViewController from another ViewController, they never get released from memory. To release them from memory you need to explicitly dismiss them.

The method presentViewController:animated:completion: sets the presentedViewController property to the specified view controller, resizes that view controller’s view and then adds the view to the view hierarchy.

So you see you are getting a stack of ViewControllers and adding a View on top of another.

Upvotes: 1

Related Questions