1, シンプルな画面遷移
Storyboard で Segueに Identifier を設定
// 画面遷移
performSegue(withIdentifier: "next", sender: nil)
↓
// 画面を消去して戻る場合
dismiss(animated: true, completion: nil)
画面遷移時に値を渡す
遷移先のViewControllerを segue.destination でインスタンス化してプロパティを更新する
Example: 次の画面のcount2に値を渡したい場合
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let nextVC = segue.destination as! NextViewController
nextVC.count2 = count
}
2,Navigation Controllerで画面遷移する
-
Product -> Embed -> Navigation Controller でNavigation Controllerを追加する
-
storyboard?.instantiateViewController でインスタンスをつくってnavigationController?.pushViewController で遷移させる
let nextVC = storyboard?.instantiateViewController(identifier: "next") as! NextViewController
navigationController?.pushViewController(nextVC, animated: true)