Manisha Singh Manisha Singh - 1 year ago 82
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 Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download