LoginSignup
3

More than 5 years have passed since last update.

[iOS]iOSアプリ開発用の骨組み

Posted at

アプリ開発の骨組み用プロジェクトを作りました。

構成としては一番メジャー?なTabBarとNavigationControllerを組み合わせたものです。

Screen Shot 2017-02-19 at 17.24.20.png

Screen Shot 2017-02-19 at 17.25.21.png

共同作業時のコンフリクトをなるべく防ぐために、TabごとにStoryboardを分割しています。

スクリーンショット 2017-02-19 17.28.47.png

AppDelegateはこんな感じ。

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    var tabController: MainTabBarController?
    var navController1, navController2: UINavigationController?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        self.tabController = MainTabBarController()

        var viewControllers: [UIViewController] = []

        // ファイル名を指定してStoryBoardを生成
        let firstStoryBoard: UIStoryboard = UIStoryboard(name: "FirstTab", bundle: nil)
        let secondStoryBoard: UIStoryboard = UIStoryboard(name: "SecondTab", bundle: nil)

        // 生成したStoryBoardのInitialViewControllerを取得
        let firstViewController: UIViewController = firstStoryBoard.instantiateInitialViewController()!
        let secondViewController: UIViewController = secondStoryBoard.instantiateInitialViewController()!

        // NavigationController
        navController1 = UINavigationController(rootViewController: firstViewController)
        navController2 = UINavigationController(rootViewController: secondViewController)

        viewControllers.append(navController1!)
        viewControllers.append(navController2!)

        self.tabController!.viewControllers = viewControllers

        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        self.window?.rootViewController = self.tabController
        self.window?.makeKeyAndVisible()

        return true
    }
    ...
}

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
3