Is there a way to present a view controller modally without knowing what the visible view controller view is? Basically sort of like you would show an alert view at any points in time.
I would like to be able to do something like:
MyViewController *myVC = [[MyViewController alloc] init]; [myVC showModally];
I'd like to be able to call this from anywhere in the app, and have it appear on top. I don't want to care about what the current view controller is.
I plan to use this to show a login prompt. I don't want to use an alert view, and I also don't want to have login presentation code throughout the app.
Any thoughts on this? Or is there maybe a better way to achieve this? Should I just implement my own mechanism and just place a view on top of the window?
You may also start segues from table rows and collection view cells. Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.
Well, you can follow the chain.
Start at [UIApplication sharedApplication].delegate.window.rootViewController
.
At each view controller perform the following series of test.
If [viewController isKindOfClass:[UINavigationController class]]
, then proceed to [(UINavigationController *)viewController topViewController]
.
If [viewController isKindOfClass:[UITabBarController class]]
, then proceed to [(UITabBarController *)viewController selectedViewController]
.
If [viewController presentedViewController]
, then proceed to [viewController presentedViewController]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With