我一直在自学如何发展,现在我已经到了需要专家指导的地步。我使用 MVC 结构以编程方式创建了一些用户界面。我的问题是如何将导航 Controller 嵌入到标签栏 Controller 中,以便我的标签栏 Controller 可以出现在每个屏幕上。我在 main.storyboard 中制作了选项卡栏 Controller ,并在我命名为 Home Controller 的 View Controller 中引用了它。
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let tabViewController = storyboard.instantiateViewController(withIdentifier: "TabBar")
self.present(tabViewController, animated: true, completion: nil)
上面的代码是在 View did load函数中。我想知道我是否需要更改应用程序委托(delegate)中的 Root View Controller ?
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let layout = UICollectionViewFlowLayout()
window?.rootViewController = UINavigationController(rootViewController: HomeController(collectionViewLayout: layout))
这是我完成的启动函数。
最佳答案
使用以下几行
var navigationController = UINavigationController(rootViewController: viewController));
tabBarController.viewControllers = [navigationController,firstViewControllersecondViewController, ]
关于ios - 如何在 Swift Xcode 8.2 中以编程方式将导航 Controller 嵌入到选项卡栏 Controller 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43164575/