1 创建三个视图控制器:FirstViewController、SecondViewController和ThirdViewController
2、修改FirstViewController.swift的viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.brown
self.navigationItem.rightBarButtonItem =
UIBarButtonItem(title:”下一页”, style:
UIBarButtonItemStyle.Plain, target:self, action:
selector(FirstViewController.nextPage))
}
3、 SecondViewController.swift的viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.purple
}
4、修改AppDelegate.swift的didFinishLaunchingWithOptions
func application(application:UIApplication,
didFinishLaunchingWithOptions launchOptions:[NSObject:
AnyObject]?) -> Bool {
let firstViewController = FirstViewController()
let thirdViewController = ThirdViewController()
let tabBarController = UITabBarController()
let navigationController =UINavigationController(rootViewController:firstViewController)
tabBarController.viewControllers =[navigationController, thirdViewController]
let tabBar = tabBarController.tabBar
let item = tabBar.items![0]
item.image = UIImage(named:“Tab1”)
item.title = “item1”
let item3 = tabBar.items![1]
item3.image = UIImage(named:“Tab3”)
item3.title = “item3”
window?.rootViewController = tabBarController
return true
}