UINavigationControllerEvent: viewController property
The viewController property is the page about to be shown, or just shown.
Value
- Read-only. Assigning to it throws
TypeError. - In
beforeshow, use it to tell which page is about to be shown; don't usenav.topViewController. - In
show, it is the same object asnav.topViewController(tested). - When the event is created with
newwithout it, it isnull.
Examples
js
const home = new UIViewController();
const nav = new UINavigationController(home);
nav.addEventListener('show', (e) => {
console.log(e.viewController === home ? '回到了首页' : '进入了下一页');
});Effect: after each switch, prints whether the page now shown is the home page or another one.
Corresponding iOS API
The viewController parameter of navigationController:willShowViewController:animated: and navigationController:didShowViewController:animated:.