xibファイルと連携する方法。
Storyboardでの画面遷移管理がまだ苦手なので・・・。
ちなみに言語の仕様や文法を完全には理解していないので、記述方法等が間違っていたらご指摘願います。
AppDelegate.swift
import UIKit
import CoreData
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication,
didFinishLaunchingWithOptions
launchOptions: NSDictionary?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
// Override point for customization after application launch.
self.window!.backgroundColor = UIColor.whiteColor()
//Create main ViewControllers
var firstViewController:FirstViewController =
FirstViewController(nibName: "FirstViewController", bundle: nil)
var secondViewController:SecondViewController =
SecondViewController(nibName: "SecondViewController", bundle: nil)
var thirdViewController:ThirdViewController =
ThirdViewController(nibName: "ThirdViewController", bundle: nil)
//Create NavigationControllers
var firstNavigationController:UINavigationController =
UINavigationController(rootViewController:firstViewController)
var secondNavigationController:UINavigationController =
UINavigationController(rootViewController:secondViewController)
var thirdNavigationController:UINavigationController =
UINavigationController(rootViewController:thirdViewController)
var naviControllerList:Array<UINavigationController> =
[
firstNavigationController,
secondNavigationController,
thirdNavigationController
]
//Create TabBarController
var tabBarController:UITabBarController = UITabBarController()
tabBarController.setViewControllers(naviControllerList, animated: true)
self.window!.rootViewController = tabBarController
self.window!.makeKeyAndVisible()
return true
}
各UIViewController init の部分が不安であるが…。
FirstViewController.swift
import Foundation
import UIKit
class FirstViewController : UIViewController
{
init(nibName:String!, bundle: NSBundle!)
{
super.init(nibName: nibName, bundle: bundle)
//Create Navigationbar
self.navigationItem.title = "First VIEW CONTROLLER"
//Create TabBar
self.title = "First"
}
override func viewDidLoad()
{
super.viewDidLoad()
}
}
SecondViewController.swift
import Foundation
import UIKit
class SecondViewController : UIViewController
{
init(nibName:String!, bundle: NSBundle!)
{
super.init(nibName: nibName, bundle: bundle)
//Create Navigationbar
self.navigationItem.title = "Second VIEW CONTROLLER"
//Create TabBar
self.title = "Second"
}
override func viewDidLoad()
{
super.viewDidLoad()
}
}
ThirdViewController.swift
import Foundation
import UIKit
class ThirdViewController :UIViewController
{
init(nibName:String!, bundle: NSBundle!)
{
super.init(nibName: nibName, bundle: bundle)
//Create Navigationbar
self.navigationItem.title = "Third VIEW CONTROLLER"
//Create TabBar
self.title = "Third"
}
override func viewDidLoad()
{
super.viewDidLoad()
}
}
この他、AppDelegate.swiftファイルでnibName設定しているxibファイルが必要となります。