我想要從AppDelegate呈現/推入嵌入在NavController中的VC。我以前使用這個代碼,但不知何故它不工作了:從AppDelegate呈現嵌入在導航控制器中的VC
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let VC = storyboard.instantiateViewControllerWithIdentifier("PendingRequest") as! PendingRequestVC
let navController = UINavigationController.self(rootViewController: VC)
let rootViewController = UIApplication.sharedApplication().keyWindow!.rootViewController
rootViewController!.presentViewController(navController, animated: false, completion: nil)
其他代碼打開我所需的VC,但不在導航窗格中。任何指導將不勝感激。
用戶與推送通知進行交互後,從AppDelegate進行調用。
編輯: 我能夠通過使用此代碼呈現正確的VC:
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if let viewController = mainStoryboard.instantiateViewControllerWithIdentifier("PendingNavController") as? UINavigationController {
if let yourViewController = viewController.topViewController as? PendingRequestVC {
//yourViewController.getRequestdata()
}
UIApplication.sharedApplication().keyWindow!.rootViewController = viewController;
}
但這種代碼不會讓我回去使用我的NavBar關閉按鈕。 我的結構如下:
TabController - > NavController1 - > VC1 - > NavController1a - > VC1a 我試圖去VC1a並能夠使用閉合按鈕返回到VC1
爲什麼你想要通過應用程序來做這件事Delegate? – lukaivicev
它是否嵌入在故事板上的導航控制器中? –
@lukesIvi我應該提到它:用戶與推送通知進行交互後的操作。 –