简体   繁体   中英

How to Navigate all views of application using Navigation Controller in ios using Swift (I am using Xib not Storyboard)

(I searched but could not find any working solution)

I have created 5 Xib's which are representing different screens of my application. Now I want to add navigation in my application so that user can go back and forth. I also want to pass data between view controllers. I have done this before, usinig Storyboard that was simple. But i do not have any idea how to do it with Xib.

I am using xcode 7.3 and swift 2.0

Proper guidelines will be highly appreciated thanks.

Try this. It may help you.

AppDelegate.swift

var window: UIWindow?
var nav:UINavigationController!

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
{
    let FirstVC = HomeViewController(nibName: "HomeViewController", bundle: nil) as HomeViewController
    let nav = UINavigationController(rootViewController: FirstVC)
    nav.navigationBarHidden = true
    self.window?.rootViewController = nav
    self.window?.makeKeyAndVisible()

    return true
}

Then when you want to push the other view controller , simple use following code to move to another view controller.

@IBAction func pushHomeVC(sender: UIButton)
{
     let homeVC = HomeViewController(nibName: "HomeViewController", bundle: nil) as HomeViewController
     // If you want to data pass in Second Screen.
     homeVC.strData = "Pass data that you want"
     let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
     appDelegate.nav.pushViewController(homeVC, animated: true) 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM