ios - 我试图为我的应用程序实现启动画面,因为它需要从 api 将数据加载到应用程序中
问题描述
我正在开发一个将数据从 api 加载到应用程序中的应用程序。我试图通过在应用程序加载之前延迟 5 秒来加载 launchScreen。但它不起作用。
这是我正在使用的代码,我将启动屏幕 storyBorad 命名为“splashController”,将主故事板命名为“initController”。
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.splashScreen()
return true
}
private func splashScreen() {
self.window?.rootViewController = UIStoryboard(name: "LaunchScreen", bundle: nil).instantiateViewController(identifier: "splashController")
self.window?.makeKeyAndVisible()
print("Timer Started")
Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(dismissSplashController), userInfo: nil, repeats: false)
}
@objc func dismissSplashController(){
self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "initController")
self.window?.makeKeyAndVisible()
}
你能调查一下吗?
解决方案
您不应该延迟应用程序委托上的启动画面,您可以通过在您的第一个视图控制器中设计与启动画面设计相同的视图来实现此行为,并在成功获取主视图控制器中的数据时隐藏此视图
推荐阅读
- android - 为什么作者在 Room with Android Jetpack 的两个位置定义表格字段?
- php - php关联数组复杂度
- c# - 在插入语句后从 SQL 数据库中检索自动增量 ID
- node.js - Node.js 上的 Selenium webdriver - 如何访问全局窗口变量
- c# - 如何编写关于 Cosmos 数据库的存储库单元测试(SQLApi + CosmosClient)
- jquery - 如何在 select2 元素中导航
- python - 'TypeError:使用opencv-python绘制圆时,参数'color'的标量值不是数字'
- python - 如何使用python在单个数据框中查找具有多个公共值的列
- django - 如何使用 DjangoORM 从两个表中获取数据?
- python - 应用关闭时不会显示通知