如何在Swift中呈现UITabBarController

Joq*_*qus 2 uitabbarcontroller uikit swift

我有一个故事野猪,视图上有一个按钮。当我单击该按钮时,我应该转到自定义的UITabBarController,但显示的只是一个空的选项卡栏。

let tabBar = TabViewController()
self.presentViewController(tabBar, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

在故事板上,我将TabBarController的类设置为TabViewController。我想念什么?

Mic*_*lum 5

您需要在Interface Builder中为TabViewController提供一个故事板ID,并通过以下方式对其进行访问:

if let tabViewController = storyboard.instantiateViewControllerWithIdentifier("TheAssignedID") as? TabViewController {
    presentViewController(tabViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

您使用的代码只是创建TabViewController类的新实例。不访问您在Interface Builder中定义的原型。