2016-11-11 235 views
0

我正在嘗試處理遠程通知。 在我的AppDelegate didReceive方法,我想開一看:禁用頂部導航欄

var storyboard = UIStoryboard(name: "Main", bundle: nil) 
     var destinationController = storyboard.instantiateViewController(withIdentifier: "InfoTraficViewController") as? InfoTraficViewController 
     destinationController?.infoTraficId = trafficInfoId 
     window?.rootViewController?.present(destinationController!, animated: true, completion: nil) 

這是工作,但不顯示在頂部導航欄。所以用戶不能上一個。

我該怎麼辦?我想:

self.navigationController?.setNavigationBarHidden(false, animated: animated) 

但它不工作

編輯:

它的工作有:

var storyboard = UIStoryboard(name: "Main", bundle: nil) 
    var destinationController = storyboard.instantiateViewController(withIdentifier: "InfoTraficViewController") as? InfoTraficViewController 
    destinationController?.infoTraficId = trafficInfoId 

    var customUiNavController = storyboard.instantiateViewController(withIdentifier: "CustomUINavigationController") as? CustomUINavigationController 
    customUiNavController?.pushViewController(destinationController!, animated: true) 

    window?.rootViewController = customUiNavController 

由於拉雅

+0

你的'windows's rootViewController應該是'navController',是嗎? – aircraft

回答

1

更改此

window?.rootViewController?.present(destinationController!, animated: true, completion: nil) 

與此

self.navigationController?.pushViewController(destinationController, animated: true) 

由於這個問題是,您是在陳述你UIViewController上的windowrootViewController,所以這ViewController是您UINavigationController的頂部。

+0

不能與窗口的AppDelegate – Xero

+0

使用self.navigationController?.rootViewController?.navigationController?.pushViewController,什麼都推 – Xero

+0

在AppDelegate中創建的UINavigationController的一個對象並將其分配給您的UINavigationController的對象,然後使用該對象中的appdelegate – Rajat