關於你的名字...和storyboard ID。
storyboard ID就是View在storyboard上的識別碼
程式碼的形狀為(withIdentifier: "...")
navigationController?.popToRootViewController(animated: true)
ViewController.swift
按下button(Go to View 2)執行的方法:
@IBAction func gotoView2(_ sender: UIButton)
初始化(生成)第二個UIViewController(lightRed):
let lightRed = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "lightRed")
推出UIViewController(由下往上push):
present(lightRed, animated: true, completion: nil)
推出UIViewController(由右至左轉場):
//navigationController?:ViewController可能會被包進navigationController,也有可能不會,故為Optional
self.navigationController?.pushViewController(lightRed, animated: true)
LightRedViewController.swift
按下button(Go to View 1)執行的方法:
@IBAction func gotoView1(_ sender: UIButton) {
navigationController?.popViewController(animated: true)
}
LightGreenViewController.swift
按下button(Go to View 2)執行的方法:
@IBAction func backtoView2(_ sender: UIButton)
回到上個畫面(由左而右轉場時的返回方式):
navigationController?.popViewController(animated: true)
回到上個畫面(由下而上轉場時的返回方式):
dismiss(animated: true, completion: nil)
回到第一個畫面:
navigationController?.popToRootViewController(animated: true)