ios - 如何在 Swift Xcode 8.2 中以编程方式将导航 Controller 嵌入到选项卡栏 Controller 中?

标签 ios swift xcode model-view-controller uitabbarcontroller

我一直在自学如何发展,现在我已经到了需要专家指导的地步。我使用 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/

相关文章:

ios - Swift 4 - 'substring(to:)' 已弃用 - 替代我的代码

ios - 在 iOS 上的 HTTP Live Streaming 客户端中拦截视频帧

ios - 无法弄清楚为什么 VideoDeviceInput 没有被添加到我的 AVCaptureSession

html - 在 HTML Swift 中编码字符串

ios - requestLocation() 在使用 Swift 2 的模拟器中总是失败

iphone - dismissModalViewControllerAnimated 产生黑色背景

objective-c - 如果不在 Xcode 6 中导入 UIKit.h,就无法访​​问 UIImage 类吗?

ios - 如何将 iOS “Open In…” 功能添加到我的导航应用程序

ios - iPad 在 subview Controller 中显示 UIActionSheet 时崩溃

ios - 如何在 Xcode 上使用不同的模块缓存路径编译 PCH