VC one 加入一個Button 為 (next)
VC two 加入一個Button 為 (exit)
按住 control 從(next) Button 拖曳到VC two上 選擇 “SHOW”
從 exit Button返回 VC one
創建VC two的ViewController
拉入exit 的 IBAction
以下程式碼
@IBAction func exitButton(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
VC one 將值傳到 VC two
拖曳一個 Click Button
在VC two設一個變數來接值
var receive: String?
在VC one 鍵入”prepare”
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let vcOne = segue.destination as?VCtwo (向下轉型的地方)
vcOne?.receive = “Hello world” (接值的變數要做什麼?)
}
在VC two 建立Click Button的@IBAction
@IBAction func clickButton(_ sender: UIButton) {
if let receive = receive {
(新變數 = 傳值的變數)
print(receive)
}
editor -> Embed in -> Navigation Controller
兩個以上的segue
在segue的idrntifier id取名 segue_to_VCtwo
在prepare function內加入
if segue.identifier == “segue_to_VCtwo” {
}