Manisha Singh Manisha Singh - 26 days ago 5
Swift Question

Method of UINavigationController to add a view controller to navigation stack?

Which method of the UINavigationController is used to add a view controller to navigation stack in swift?

Answer

Normally, the following method is used to push UIViewController to UINavigationController's navigation stack

pushViewController(_ viewController: UIViewController, animated: Bool)

This is implemented inside your CustomViewController class in the following way:

let someVC: CustomViewController = CustomViewController() // this is one way of initializing it
self.navigationController?.pushViewController(someVC, animated: true)

The following is another method which can be used to add a UIViewController to UINavigationController stack

setViewControllers(_ viewControllers: [UIViewController], animated: Bool)