I want to transition from ViewController to secondViewController, when the user presses a UIButton, using code only in Swift.
//Function to transition
func
SWIFT
Usually for normal transition we use,
let next:SecondViewController = SecondViewController()
self.presentViewController(next, animated: true, completion: nil)
But sometimes when using navigation controller, you might face a black screen. In that case, you need to use like,
let next:ThirdViewController = storyboard?.instantiateViewControllerWithIdentifier("ThirdViewController") as! ThirdViewController
self.navigationController?.pushViewController(next, animated: true)
Moreover none of the above solution preserves navigationbar when you call from storyboard or single xib to another xib. If you use nav bar and want to preserve it just like normal push, you have to use,
Let's say, "MyViewController" is identifier for MyViewController
let viewController = MyViewController(nibName: "MyViewController", bundle: nil)
self.navigationController?.pushViewController(viewController, animated: true)