Skip to content

UINavigationController() constructor ​

The UINavigationController() constructor creates a navigation controller.

Syntax ​

new UINavigationController()
new UINavigationController(rootViewController)

Parameters ​

rootViewController

Optional; a UIViewController to be the bottom of the stack. If omitted, the stack is empty; add view controllers later with pushViewController() or viewControllers.

Return value ​

A new UINavigationController.

Exceptions ​

TypeError

Examples ​

js
const empty = new UINavigationController();
const withRoot = new UINavigationController(new UIViewController());
console.log(empty.viewControllers.length, withRoot.viewControllers.length);

Result: The console prints 0 1.

Corresponding iOS API ​

-[UINavigationController initWithRootViewController:]; with no argument, init.

See also ​