如何在UITabBarController中加载所有视图? [英] How to load all views in UITabBarController?

查看:64
本文介绍了如何在UITabBarController中加载所有视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与此问题相关的帖子中找不到相关和最新的答案。

I have not found relevant and up to date answers in the posts related to this question.

我想在启动时加载所有viewcontrollers。目前按预期启动,但是当我点击一个条形项目(第一次)时,加载它会有一点延迟,因为它尚未加载。

I would like to load all viewcontrollers on launch. Currently it launches as expected but when I tap on a bar item (the first time) there is a slight delay to load it because it has not been loaded yet.

如何我能做到的是Swift吗?

How can I do that is Swift ?

谢谢。

推荐答案

To预加载 UIViewController 的视图,只需访问其视图属性:

To preload a UIViewController's view, simply access its view property:

let _ = myViewController.view

预加载 UITabBarController 上的所有视图控制器,你可以这样做:

To preload all view controllers on a UITabBarController, you can do:

if let viewControllers = tabBarController.viewControllers {
    for viewController in viewControllers {
        let _ = viewController.view
    }
}

或更紧凑:

tabBarController.viewControllers?.forEach { let _ = $0.view }

这篇关于如何在UITabBarController中加载所有视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆