简体   繁体   中英

How to present new ViewController and dismiss the current from memory

How to present new ViewController and dismiss the current from memory

 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. 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 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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