简体   繁体   English

如何等待加载ViewController直到appdelegate func应用程序完成

[英]how to do to wait to load ViewController until appdelegate func application will be completed

I would like to know which is the best way to do the next: 我想知道哪种是下一步的最佳方法:

In my AppDelegate.swift file I had the entry point of the app, register the instance, but before the instance is registered, the main function(inside viewDidLoad() ) of the MainViewController is called and I would like to know how to do to wait the MainViewController viewDidLoad() function until the instance register will be completed. 在我的AppDelegate.swift文件中,我有应用程序的入口点,注册了实例,但是在注册实例之前,调用了MainViewController的main函数(在viewDidLoad()里面),我想知道该怎么做。等待MainViewController viewDidLoad()函数,直到实例寄存器将完成。

You should add extra view controller and show that view controller initially until your required task got completed. 您应该添加额外的视图控制器并在最初显示该视图控制器,直到完成所需的任务。 You can show loader or activity indicator or some ui that shows like getting data or etc. After you completed your process move to main viewcontroller so your viewDidload will be called when you want! 您可以显示加载器或活动指示器,或显示诸如获取数据等之类的ui。完成过程后,移至主viewcontroller,以便在需要时调用viewDidload!

ViewDidLoad is Async by design, so is a non-sense waiting for it. ViewDidLoad在设计上是异步的,所以在等待它是胡说八道。 When called you are certain UI is up, it was written for this scope. 当调用您确定UI已启动时,它是为此范围编写的。 I think is better you read carefully iOS event loop and app lifecycle, to fully undestand Apple design. 我认为最好仔细阅读iOS事件循环和应用程序生命周期,以完全理解Apple的设计。

您可以使用sleep()函数等待加载viewcontrollers视图

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

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