1
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 5 years have passed since last update.

[XCODE]Tabbed ApplicationでStoryboardを分割する

Posted at

概要

iOSのTabbedApplicationのStoryboardをタブごとに分割する方法です。

手順

  1. Tabbed Applicationを作成します
スクリーンショット 2017-01-22 16.49.53.png スクリーンショット 2017-01-22 16.51.17.png

2.各タブごとのstoryboardを新規作成する
今回は、First.storyboardとSecond.storyboardを作成します。
スクリーンショット 2017-01-22 16.53.48.png

3.Main.storyboardのFirstViewControllerとSecondViewControllerを2で作成したstoryboardに各々カットアンドペーストする

4.First.storyboardとSecond.storyboardの「Is initial View Controller」のチェックをONにする
スクリーンショット 2017-01-22 16.57.30.png

5.MainTabBarControllerを新規作成する
スクリーンショット 2017-01-22 17.05.08.png

6.Main.storyboardのTabBarControllerのClassに5で作成したクラスを設定する
スクリーンショット 2017-01-22 17.06.57.png

7.MainnTabBarControllerのViewDidLoadに以下のコードを追加

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSMutableArray *viewControllers = [NSMutableArray new];
    
    // ファイル名を指定してStoryBoardを生成
    UIStoryboard *firstStoryBoard = [UIStoryboard storyboardWithName:@"First" bundle:[NSBundle mainBundle]];
    UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"Second" bundle:[NSBundle mainBundle]];
    
    // 生成した StoryBoard の InitialViewController を取得する
    UIViewController *firstViewController = [firstStoryBoard instantiateInitialViewController];
    UIViewController *secondViewController = [secondStoryBoard instantiateInitialViewController];
    
    // ViewControllersにUIViewControllerを追加する
    [viewControllers addObject:firstViewController];
    [viewControllers addObject:secondViewController];
    
    // TabBarControllerの持つViewControllerの配列に代入
    self.viewControllers = viewControllers;
}

8.実行!
Screen Shot 2017-01-22 at 17.22.52.png
Screen Shot 2017-01-22 at 17.22.57.png

メリット

Storyboardを分割することによってチーム開発時のコンフリクトを防ぐことが出来ます。

参考にした記事

1
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
1
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?