Skip to content

UINavigationController: show event ​

The show event fires when the navigation controller has shown a view controller and the transition animation has finished.

Syntax ​

nav.addEventListener('show', (event) => { })

Event object ​

Event, with one extra field:

FieldTypeMeaning
viewControllerUIViewControllerThe view controller that has been shown

The type definitions don't yet have a type for this event object; annotate the viewController field yourself, as shown in the example.

Not cancelable.

When it fires ​

  • Fires when code pushes a view controller; also fires when the user taps the back button or swipes back, and both cases receive the same event (measured). When you need to tell push from pop, compare nav.viewControllers.length before and after the transition.
  • When it fires, nav.viewControllers is already the stack after the transition (measured). So any "current path" or "current level" your code keeps separately should be realigned here with nav.viewControllers.
  • Whether it fires when code calls the popViewController() family of methods is not verified in the simulator.
  • Whether it fires when the bottom view controller is first shown after the app launches is not verified in the simulator.
  • The callback doesn't run synchronously at the moment of the transition; it runs a little later. See How the runtime works.

Examples ​

js
const nav = new UINavigationController(new UIViewController());
nav.addEventListener('show', (ev) => {
  const event = /** @type {Event & { viewController: UIViewController }} */ (ev);
  console.log(event.type, event.target === nav, event.viewController === nav.topViewController);
});

Effect: Each time a transition finishes, it prints show true true.

Corresponding iOS API ​

navigationController:didShowViewController:animated: on UINavigationControllerDelegate.

See also ​