UIViewController: presentingViewController property
The presentingViewController property is the view controller that presented this one.
Value
A UIViewController, or null.
- Read-only; assigning to it throws
TypeError. - The default is
null: not presented modally. - Becomes the presenter when presented, and goes back to
nullafter dismissal. There is no dedicated change event; seepresentedViewController.
Note: After
a.presentViewController(b),b.presentingViewControlleris not necessarilya. Whenais on a navigation stack, it is theUINavigationControllerthatais in: the system hands the presentation to the nearest container. Whether it isawhenais in no container is not verified in the simulator.
Examples
const host = new UIViewController();
const nav = new UINavigationController(host);
const modal = new UIViewController();
async function show() {
await host.presentViewController(modal, { animated: false });
console.log(host.presentedViewController === modal);
console.log(modal.presentingViewController === host);
console.log(modal.presentingViewController === nav);
}Result: Calling show() while nav is the window's root view controller prints true, false, true in order.
Checking whether a view controller is presented modally:
const sheet = new UIViewController();
if (sheet.presentingViewController) {
console.log('sheet is being presented modally');
} else {
console.log('sheet is not presented modally');
}Result: Before sheet is presented, prints sheet is not presented modally. After it is presented, prints sheet is being presented modally.
Corresponding iOS API
UIViewController.presentingViewController.