Showing posts with label Navigation Controller. Show all posts
Showing posts with label Navigation Controller. Show all posts

Wednesday, 21 February 2018

Swift - Navigation Controller

App Delegate
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var home: HomeViewController = HomeViewController(nibName: "HomeViewController", bundle: nil)
var nav_ctlr: UINavigationController = UINavigationController(rootViewController: home)
self.window.rootViewController = nav_ctlr
self.window.makeKeyAndVisible()
UIApplication.sharedApplication().statusBarHidden = true
return true


View Controller
@IBAction func Landing(sender: AnyObject)   
{
        let land_vc = LandingViewController(nibName:"LandingViewController", bundle:nil)
        self.navigationController?.pushViewController(land_vc, animated: true)
}

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
    }
}