LoginSignup
1
2

More than 1 year has passed since last update.

[Xcode] Storyboard IDの2つの用途

Last updated at Posted at 2020-09-12

今日からでもすぐに取り入れられて、

  • コードをよりクリーンにできる、とか
  • 工数を削減できる、とか

そんなTipsを紹介していく記事シリーズです。
「知らなかった」「気づかなかった」「忘れていた」そんな誰かの役に立てば幸いです。

前提環境

  • Xcode 11.3.1
  • Swift 5.1.3

割とメジャーなStoryboard IDの用途

こちらの記事にあるように、
画面遷移をコードで行う場合に、StoryboardからUIViewControllerのインスタンスを取得するために使う、という用途です。
【Swift】画面遷移の方法まとめ - Segueを使わない画面遷移

(たぶん)マイナーなStoryboard IDの用途

Storyboard Referenceによって、Storyboard-AからStoryboard-Bに遷移する場合に、Storyboard-Bの先頭じゃなく後方のUIViewControllerに遷移したい時に使う、という用途です。

Storyboard-B(遷移先)

後方のViewController(この例ではFourthViewController)に任意のStoryboard IDを設定しておきます。
スクリーンショット 2020-09-11 16.20.17.png

Storyboard-A(遷移元)
スクリーンショット 2020-09-12 9.24.01.png
↑FirstViewControllerからStoryboard-BのFourthViewControllerに遷移する導線があります(赤枠部分)。

↓このStoryboard Referenceで、「Referenced ID」に上で設定したStoryboard IDを指定します。
そうするとFirstViewControllerからStoryboard-BのFourthViewControllerに遷移できます。
スクリーンショット 2020-09-12 9.25.59.png

このように、Storyboard IDをうまく使うことで、1つのStoryboardで複数の導線をカバーすることができます。

1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2