Current view controller from AppDelegate?

If your app’s root view controller is a UINavigationController you can do this: ((UINavigationController*)appDelegate.window.rootViewController).visibleViewController; Similarly, if it’s a UITabBarController you can do this: ((UITabBarController*)appDelegate.window.rootViewController).selectedViewController; Of course, explicit casting like this is dirty. Better would be to capture the reference yourself using strong types.

How to identify previous view controller in navigation stack

You could use the UINavigationController‘s viewControllers property: @property(nonatomic, copy) NSArray *viewControllers Discussion: The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array. https://developer.apple.com/documentation/uikit/uinavigationcontroller You could use that to … Read more

Swift – How to dismiss all of view controllers to go back to root

Try This : self.view.window?.rootViewController?.dismiss(animated: true, completion: nil) it should dismiss all view controllers above the root view controller. If that doesn’t work than you can manually do that by running a while loop like this. func dismissViewControllers() { guard let vc = self.presentingViewController else { return } while (vc.presentingViewController != nil) { vc.dismiss(animated: true, completion: … Read more

iOS Nested View Controllers view inside UIViewController’s view?

No, this is generally good design, it helps keep your view controllers concise. However you should be using the view controller containment pattern, take a look at the following documentation. Implementing a Container View Controller This is incredibly simple to setup using Interface Builder with Storyboards as well, take a look at the Container View … Read more

Why can’t I call the default super.init() on UIViewController in Swift?

The designated initialiser for UIViewController is initWithNibName:bundle:. You should be calling that instead. See http://www.bignerdranch.com/blog/real-iphone-crap-2-initwithnibnamebundle-is-the-designated-initializer-of-uiviewcontroller/ If you don’t have a nib, pass in nil for the nibName (bundle is optional too). Then you could construct a custom view in loadView or by adding subviews to self.view in viewDidLoad, same as you used to.

How to get root view controller?

if you are trying to access the rootViewController you set in your appDelegate. try this: Objective-C YourViewController *rootController = (YourViewController*)[[(YourAppDelegate*) [[UIApplication sharedApplication]delegate] window] rootViewController]; Swift let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate let viewController = appDelegate.window!.rootViewController as YourViewController Swift 3 let appDelegate = UIApplication.shared.delegate as! AppDelegate let viewController = appDelegate.window!.rootViewController as! YourViewController Swift 4 & 4.2 … Read more