我有两个名为MeasurementsVC.swift和OutfitBuilder.swift的UIViewController类。但是,我没有这些UIViewControllers的nib文件。我想将它们加载到UITabBarController中,以便在两个UIViewControllers之间切换。基于断the swift swift tutorial,我有我的AppDelegate文件在swift中添加没有nib文件的UIViewControllers到UITabBarController
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?这两个UIViewControllers都可以自己运行。我作为唯一的UIViewController在单独的项目中创建它们。
如果你尝试:let myVC1 = OutfitBuilderVC() – 2014-12-04 03:15:38
这些控制器的视图在哪里制作?在代码中? – rdelmar 2014-12-04 04:14:35
是否有一个特定的原因,你不只是从默认的应用程序模板和使用故事板制作标签栏? – Ian 2014-12-04 06:30:04