您的位置:首页 > 移动开发 > Swift

Swift NavigationController的使用

2016-04-06 16:11 519 查看

一、创建导航条

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

self.window?.backgroundColor = UIColor.whiteColor()
let firstVC = FirstViewController(nibName:nil,bundle: nil)
let navigation = UINavigationController(rootViewController: firstVC)
self.window?.rootViewController = navigation;

return true
}


二、导航条上添加按钮

let item = UIBarButtonItem(title: "下一个", style: UIBarButtonItemStyle.Plain, target: self, action: "buttonClick:")
self.navigationItem.rightBarButtonItem = item


三、跳转到下一个界面

func buttonClick(button:UIButton) {
let secondVC = SecondViewController(nibName:nil,bundle: nil)
self.navigationController?.pushViewController(secondVC, animated:true)
}


四、返回到上一个界面

func back() {
self.navigationController?.popViewControllerAnimated(true)
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  swift 导航