0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

既存のアプリのstoryboardを分割する方法。(storyboard reference)

Posted at

0. はじめに

こんな感じで、1つのstoryboardに複数のviewControllerが設置されているのは良くないので、これを分割することを考えます。おそらく実務とかでも分割するということで統一されているので、できるようになっておいて損はないはずです。
スクリーンショット 2021-04-28 19.36.22.png

1. storyboard referenceを設置して、segueで接続

次のstoryboardファイルへの道しるべみたいなものです。
スクリーンショット 2021-04-28 19.40.54.png

2. 新しくstoryboardファイルを作成する

ここに分割する対象のviewControllerを設置します。storyboardフォルダ等を作成して、まとめておくと良いです。
スクリーンショット 2021-04-28 19.42.48.png

3. 分割したいviewControllerを、新しく作成したstoryboardファイルにコピペ!

左のリストから選択すると楽です。
コピーして
スクリーンショット 2021-04-28 19.44.49.png
ペースト
スクリーンショット 2021-04-28 19.45.28.png
コピペが終わったら、元のViewControllerは削除しても大丈夫です。

4. identifierなど、その他諸々の設定

segueのidentifierを設定してください。
スクリーンショット 2021-04-28 19.49.06.png
次に、最初に設置した、storyboard referenceのinspectorから、遷移したいviewControllerがあるstoryboardファイルを選択してください。storyboard referenceの見た目の少し変わるはずです。
スクリーンショット 2021-04-28 19.49.38.png
さいごに、遷移する先のstoryboardファイルのviewcontrollerのinspectorから、is initial view controllerにチェックを入れてください。これは新しいstoryboardに遷移したとしても、その中のどのviewControllerに移ればよいかを、xcodeがわからないためです。
スクリーンショット 2021-04-28 19.51.49.png
これでstoryboard referenceで遷移ができるようになりました!

5. 1-4を繰り返して、一つのstoryboardに一つのviewControllerが含まれるようにする。

これが完了すれば、だいぶスッキリして保守しやすくなるはずです。
何か質問あればコメントしてください!

0
2
0

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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?