1

When APP is Launching - start SigninView - it's Okey. Next if success - I need showTripController(). Function work but nothing show? What's a problem?

func showSigninView() {
    let controller = self.window?.rootViewController!.storyboard?.instantiateViewControllerWithIdentifier("DRVAuthorizationViewController")
    self.window?.rootViewController!.presentViewController(controller!, animated: true, completion: nil)
}

func showTripController() {
    let cv = self.window?.rootViewController!.storyboard?.instantiateViewControllerWithIdentifier("DRVTripTableViewController")
    let nc = UINavigationController()
    self.window?.rootViewController!.presentViewController(nc, animated:true, completion: nil)
    nc.pushViewController(cv!, animated: true);
}
ilovecomputer
  • 4,238
  • 1
  • 20
  • 33

2 Answers2

0

First of all you must add this before you use window :

self.window.makeKeyAndVisible()

Another thing to keep in mind is:

Sometimes keyWindow may have been replaced by window with nil rootViewController (showing UIAlertViews, UIActionSheets on iPhone, etc), in that case you should use UIView's window property.

So, instead of using rootViewController, use the top one presented by it:

extension UIApplication {
    class func topViewController(base: UIViewController? = UIApplication.sharedApplication().keyWindow?.rootViewController) -> UIViewController? {
        if let nav = base as? UINavigationController {
            return topViewController(base: nav.visibleViewController)
        }
        if let tab = base as? UITabBarController {
            if let selected = tab.selectedViewController {
                return topViewController(base: selected)
            }
        }
        if let presented = base?.presentedViewController {
            return topViewController(base: presented)
        }
        return base
    }
}

if let topController = UIApplication.topViewController() {
    topController.presentViewController(vc, animated: true, completion: nil)
}
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
0

Replace last 3 lines of showTripController as below:

let nc = UINavigationController(rootViewController: cv));
self.window!.rootViewController = nc
Arun Gupta
  • 2,628
  • 1
  • 20
  • 37