Last Updated: July 05, 2019
·
602
· isuruj

Working With .xib Files

Loading a view controller as the initial view controller.

In the didFinishLaunchingWithOptions method in the AppDelegate,

let viewController = ViewController(nibName: "ViewController", bundle: nil)
self.window!.rootViewController = viewController

Embed the app in a UINavigationViewController.

In the didFinishLaunchingWithOptions method in the AppDelegate,

let viewController = ViewController(nibName: "ViewController", bundle: nil)
let navController = UINavigationController(rootViewController: viewController)
self.window!.rootViewController = navController

Modally present a view controller.

let modalViewController = ModalViewController(nibName: "ModalViewController", bundle: nil)
presentViewController(modalViewController, animated: true, completion: nil)

Modally present a view controller embedded inside a UINavigationViewController.

let modalViewController = ModalViewController(nibName: "ModalViewController", bundle: nil)
let navController = UINavigationController(rootViewController: modalViewController)
presentViewController(navController, animated: true, completion: nil)

Push to a view controller.

let viewController = ViewController(nibName: "ViewController", bundle: nil)
let navController = UINavigationController(rootViewController: viewController)
navigationController?.pushViewController(viewController, animated: true)