【发布时间】:2015-02-01 19:21:04
【问题描述】:
我有两个 UIViewController 类,分别称为 MeasurementsVC.swift 和 OutfitBuilder.swift。但是,我没有这些 UIViewControllers 的 nib 文件。我想将它们加载到 UITabBarController 中,以便可以在两个 UIViewController 之间切换。基于the swift swift tutorial,我的 AppDelegate 文件中有以下内容
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.
let tabBarController = UITabBarController()
let myVC1: UIViewController = OutfitBuilderVC()
let myVC2: UIViewController = MeasurementsVC()
let controllers = [myVC1,myVC2]
tabBarController.viewControllers = controllers
window?.rootViewController = tabBarController
let image1 = UIImage(named: "tshirtIcon.jpg")
let image2 = UIImage(named: "measureTape.jpg")
myVC1.tabBarItem = UITabBarItem(title: "tshirtIcon", image: image1, tag: 1)
myVC2.tabBarItem = UITabBarItem(title: "measureTape", image: image2, tag:2)
return true
}
现在显示的只是一个蓝屏,底部有一个灰色的标签。我认为问题可能出在线条上
let myVC1: UIViewController = OutfitBuilderVC()
let myVC2: UIViewController = MeasurementsVC()
我应该如何调用这些现有的 UIViewControllers?两个 UIViewController 都可以独立运行。我在单独的项目中将它们创建为唯一的 UIViewController。
【问题讨论】:
-
如果你尝试:让 myVC1 = OutfitBuilderVC()
-
这些控制器的视图是在哪里制作的?在代码中?
-
您不只是使用默认应用模板制作标签栏并使用情节提要,是否有特定原因?
-
@MikeTaverne 我试过了,我得到了与灰色标签相同的蓝屏。
-
这些行很好,如果您在代码中创建视图。我测试了你的代码,它对我来说很好。您可能需要向子控制器展示您在做什么。
标签: ios swift uiviewcontroller uitabbarcontroller