从appDelegate我想访问一个嵌入了UINavigation控制器的视图控制器。
我怎么能这样做,知道我可以直接访问那个视图控制器,但在这种情况下导航栏不会出现,因此这不是我想要的。
我已尝试下面找到的代码,但它会提示警告并显示黑屏。
var storyboard1 = UIStoryboard(name: "Main", bundle: nil)
var viewController: ExamNav_ViewController = storyboard1.instantiateViewControllerWithIdentifier("ExamNav_ViewController") as! ExamNav_ViewController
var rootViewController = self.window!.rootViewController as! UINavigationController
// rootViewController.pushViewController(viewController, animated: true)
rootViewController.presentViewController(viewController, animated: true, completion: nil)
警告是:尝试在UINavigationController上显示PlayMyWay.ExamNav_ViewController:0x14fd19b50:0x14fd13a90,其视图不在窗口层次结构中!
答案 0 :(得分:0)
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let navController: UINavigationController = UIStoryboard(name: "Main", bundle:nil).instantiateViewControllerWithIdentifier("provaNavController") as UINavigationController
window?.rootViewController = navController
window?.makeKeyAndVisible()
答案 1 :(得分:0)
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var objOrderVC = storyboard.instantiateViewControllerWithIdentifier("ExamNav_ViewController") as! ExamNav_ViewController
let navig = UINavigationController(rootViewController: objOrderVC)
navig.setNavigationBarHidden(false, animated: false)
window?.rootViewController = navig