pushviewcontroller swift code example
Example 1: navigationcontroller.pushviewcontroller
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let navigat = UINavigationController()
let vcw = ViewController(nibName: "ViewController", bundle: nil)
navigat.pushViewController(vcw, animated: false)
self.window!.rootViewController = navigat
self.window!.makeKeyAndVisible()
return true
}
@IBAction func GoToNext(sender : AnyObject)
{
let ViewController2 = ViewController2(nibName: "ViewController2", bundle: nil)
self.navigationController.pushViewController(ViewController2, animated: true)
}
Example 2: swift push view controller
let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "IKDetailVC") as? IKDetailVC
self.navigationController?.pushViewController(vc!, animated: true)
Example 3: swift push view controller programmatically
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "nextView") as! NextViewController
self.present(nextViewController, animated:true, completion:nil)