简体   繁体   English

如何呈现新的ViewController并从内存中消除当前电流

[英]How to present new ViewController and dismiss the current from memory

How to present new ViewController and dismiss the current from memory 如何呈现新的ViewController并从内存中消除当前电流

 var presentingViewController :UIViewController! = self.presentingViewController;

    self.dismissViewControllerAnimated(false) {
        // go back to MainMenuView as the eyes of the user
        presentingViewController.dismissViewControllerAnimated(false, completion: nil)

    }

this is ok but I want to present before dismiss to can show loading indicator 可以,但是我想在解散前显示可以显示加载指示器

let loadingNotification = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
    loadingNotification.labelText = "Retrieving Data"

If it takes a long time before the view containing "Retrieving Data" appears, there is probably too much time consuming logic in the initialization code. 如果花很长时间才出现包含“检索数据”的视图,则初始化代码中的逻辑可能太耗时。 You should consider moving it to viewDidAppear or to a background thread. 您应该考虑将其移动到viewDidAppear或后台线程。 This way the presented view controller gets shown right away (with an initial state of "Retrieving Data". 这样,显示的视图控制器就立即显示出来(初始状态为“正在检索数据”。

Another way of doing this is to create an intermediate view controller that only shows the "Retrieveing Data" message, present it instead of your new view controller and make it present the new one upon completion of the data retrieving process. 完成此操作的另一种方法是创建一个仅显示“正在检索数据”消息的中间视图控制器,而不是新的视图控制器将其显示,并在数据检索过程完成后使其呈现新的视图控制器。

The solution will depend greatly on the mechanisms your using to implement the data retrieval. 解决方案将在很大程度上取决于您用于实现数据检索的机制。 Whether it is synchrounous or asynchronous will have a big impact on how to approach it. 无论是同步还是异步都会对如何实现产生很大的影响。

As a general rule, you should avoid placing time sensitive or cpu intensive code in initialization functions such as viewDidLoad, viewWillAppear ... 通常,应避免将对时间敏感或占用大量CPU的代码放在初始化函数(例如viewDidLoad,viewWillAppear ...)中。

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

相关问题 如何在Swift中关闭当前的ViewController并更改为新的ViewController? - How to dismiss the current ViewController and change to the new ViewController in Swift? 如何在导航控制器中从下到上呈现/关闭视图控制器? - How can i present/dismiss viewcontroller from bottom to top in navigationcontroller? 如何关闭并推送新的ViewController - How to dismiss and push new ViewController Swift 在呈现新的 ViewController 后关闭当前的 ViewController - Swift dismiss current Viewcontroller after presenting new ViewController 关闭当前的UIViewcontroller并呈现一个新的UiViewController - dismiss current UIViewcontroller and present a new UiViewController 在使用Swift展示新的Viewcontroller后如何关闭以前的Viewcontroller? - How to dismiss previous Viewcontroller after presenting new Viewcontroller using Swift? 存在新控制器并关闭当前控制器时出现黑屏 - Black screen when present new controller and dismiss current controller 关闭当前的模式视图控制器,然后显示新的模式视图控制器 - Dismiss current modal view controller and then present new modal view controller 如何从UIAlertcontroller中消除模式ViewController - How to dismiss modal ViewController from UIAlertcontroller 如何从另一个位置关闭 viewController - How to dismiss a viewController from another location
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM