備忘録

Xcode memo 1:同じstoryboard内での画面遷移(Segue)

  1. Main.storyboardに遷移先用のUIViewControllerを配置。
    Object Libraryからドラッグ。
  2. 遷移先用のViewController.swiftを生成。
    File > New > File...
    または
    左のフォルダで右クリック > New File...
    Cocoa Touch Class を選択。
    Subclass of は UIViewController に変更。
  3. 作成したUIViewControllerとViewController.swiftの紐付け。
    UIViewControllerの上の黄色い何かを選択。
    Show the Identity inspector > Custom Class > Class
    ②のViewController.swiftのClass名を選択。
  4. 遷移用ボタンの配置。
    遷移元、先に1つずつ。
  5. Segueの設定。(遷移元 → 遷移先)
    遷移元のボタンから遷移先UIViewControllerにcontrolキー押しながらドラッグ。
    離すと表示されるAction SegueではShowを選択。
    (Showが最もスタンダードな遷移方法らしい)
    Main.storyboardで遷移元から遷移先に矢印が出ていたらOK。
  6. Unwind Segueの設定(遷移先 → 遷移元)
    遷移元に下記を追加。
    @IBAction func backToMe(segue: UIStoryboardSegue) {}
    Main.storyboard > 遷移先UIViewController上のExitまで
    配置したボタンをcontrolキー押しながらドラッグ。
    離すと表示されるAction Segueで上記のFunc名を選択。
    storyboard上でボタンを選択。
    Show the connections inspector > Triggered Segues で
    設定したUnwind Segueが表示されていればOK。

 

-備忘録

© 2025 ネオニート