在我的应用程序中,一旦用户从 LoginViewController
登录,他就会被定向到 ProfileTabBarController
。
ProfileTabBarController
是 UITabBarController
的子类。它由三个 View Controller 组成,所有这些都需要对 Profile 实例的引用。
当 ProfileTabBarController
被推送时,它会加载用户的配置文件。成功加载配置文件后,它会在其每个 View Controller 上设置对配置文件的引用,然后将它们添加为选项卡项。
我选择这种方法的原因是,如果用户启动应用程序并且他的 token 尚未过期,应用程序应该直接转到 ProfileTabController
;用户无需再次登录。与其在 AppDelegate
和 LoginViewController
中复制加载配置文件的代码,不如将其封装在 ProfileTabBarController
中。
这种方法的问题在于,在转场期间,UITabBarController
显示为黑色,因为尚未设置 View Controller 。我设法通过创建一个 LoadingViewController
并将其最初设置为 ProfileTabController
的唯一 UIViewController
我的问题是是否有更好的方法来解决这个问题。我真的不喜欢让 UIViewController
没有其他目的然后显示加载图标的想法。
最佳答案
呈现一个没有 View 的选项卡 View Controller 没有多大意义,所以我认为给它一个 View Controller 来处理这种加载状态的解决方案非常有意义。加入一些很酷的动画来让用户开心。
也有可能出现问题,配置文件可能无法正确加载。这个过渡 View Controller 似乎是放置代码以处理可能的错误的好地方。
关于ios - 在将 ViewController 添加到 UITabBarController 之前加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35104280/