0%

[swift]Navigation Controller (1) 畫面切換

  • 先拉一個Navigation Controller到StoryBoard,並將起始指標指向它

  • 接著拉個ViewA並且設定他為root view並且執行看看

    執行結果首頁就是剛剛指定root view的那一頁了

  • 接著在拉第二個ViewB,並將ViewA與ViewB做Push的關聯

    接著設定這個push segue的identifier

  • 在ViewA做已下修改 ```swift
    import UIKit
    class Page_A_ViewController: UIViewController {

    override func viewDidLoad() {
    super.viewDidLoad()
    //NavBar
    self.navigationController?.navigationBar.barTintColor = UIColor(red: 0.58, green: 0.761, blue: 0.231, alpha: 1)
    let titleDic : NSDictionary = [NSForegroundColorAttributeName : UIColor.whiteColor()]; //字的顏色
    self.navigationController?.navigationBar.titleTextAttributes = titleDic;
    self.navigationController?.navigationBar.tintColor = UIColor.whiteColor() //按鈕的顏色
    //設定右上角的按鈕let barOptionIcon : UIBarButtonItem = UIBarButtonItem(image: UIImage(named: “icon-options”), style: UIBarButtonItemStyle.Plain, target: self, action: “PushToOptionController:”);
    self.navigationController?.navigationBar.topItem?.setRightBarButtonItem(barOptionIcon, animated: true) ;
    }

    //右上角Button按下時觸發的事件
    func PushToOptionController(sender: UIBarButtonItem) {
    self.performSegueWithIdentifier(“toPageB”, sender: self);
    }

    }

```

  • 完成後試試看,點擊右上角的按鈕即可跳到第二頁了!!