Swift NavigationController的使用

一、创建导航条

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,导航)