Skip to content

UINavigationControllerEvent ​

UINavigationControllerEvent represents a navigation controller about to show, or having shown, a page.

The beforeshow and show events of UINavigationController are this class, and viewController is that page. Both pushing and going back fire them; no field on the event tells which one happened.

Inheritance: Event → UINavigationControllerEvent

Constructor ​

UINavigationControllerEvent()

Creates a UINavigationControllerEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.

Instance properties ​

Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.

PropertyDescription
viewController read-onlyThe page about to be shown, or just shown

These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.

Events that use this class ​

ObjectEvents
UINavigationControllerbeforeshow, show

It can't be canceled: cancelable is false, and preventDefault() has no effect, so it can't keep the user from going back.

Examples ​

js
const nav = new UINavigationController(new UIViewController());
nav.addEventListener('show', (e) => {
  console.log(e instanceof UINavigationControllerEvent, e.viewController === nav.topViewController);
});
nav.pushViewController(new UIViewController(), { animated: true });

Effect: after the pushed page is shown, prints true true.

Corresponding iOS API ​

ObjCJS
navigationController:willShowViewController:animated:beforeshow
navigationController:didShowViewController:animated:show
The viewController parameterevent.viewController

See also ​