[英]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.