Wednesday 21 February 2018

Single View Controller Changed to Navigation Controller in Swift

Single View Controller Changed to Navigation Controller in Swift

Step 1: Create a project using Single View Controller as Swift

Step 2: Remove the Main.Storyboard & ViewController

Step 3: Remove the Storyboard column in Info.plist file

Step 4: Create a New File as HomeViewController, Also create a Xib & Language as Swift

Step 5: Add the Codes in AppDelegate.Swift file

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
    {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        self.window!.backgroundColor = UIColor.whiteColor()
       
        // Create a nav/vc pair using the custom ViewController class
        var navigation_controller = UINavigationController()
        let view_controller = HomeViewController(nibName:"HomeViewController", bundle:nil)
       
        // Push the vc onto the nav
        navigation_controller.pushViewController(view_controller, animated: true)
       
        // Set the window’s root view controller
        self.window!.rootViewController = navigation_controller
       
        // Present the window
        self.window!.makeKeyAndVisible()
        return true
    }
}

No comments: