简体   繁体   English

呈现另一个后关闭UIViewController

[英]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: 我正在开发一个单视图iOS 5.0+应用程序,我将以这种方式导航抛出ViewController:

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? 我的问题是,如果我打开SearchViewControllerHomeViewController ,是HomeViewController解雇后SearchViewController显示?

I have a lot of UIViewController s and I don't know if all of them will be on memory while user is navigating between them. 我有很多UIViewController ,我不知道当用户在它们之间导航时它们是否都在内存中。

If You want to Present Only one Viewcontroller you can try like, 如果您只想展示一个Viewcontroller,可以尝试一下,

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


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

When you present a ViewController from another ViewController , they never get released from memory. 当您从另一个ViewController提供一个ViewController ,它们永远不会从内存中释放出来。 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. 方法presentViewController:animated:completion:将presentedViewController属性设置为指定的视图控制器,调整该视图控制器视图的大小,然后将该视图添加到视图层次结构中。

So you see you are getting a stack of ViewControllers and adding a View on top of another. 因此,您将看到一堆ViewController,并在另一个之上添加一个View。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM