2017-04-24 43 views
1

swift3,xcode8 IOSswift3學嘗試提出〜誰的觀點是不是在窗口層次

我創建調用上的小工具按鈕的應用程序來顯示特定頁面App

例如,一個應用程序由viewA和viewB組成,第一個視圖是viewA 我試圖在按下按鈕中的按鈕時顯示viewB。

來源


let mainStoryboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil) 
let DetailView: Detail_Update_View = mainStoryboard.instantiateViewController(withIdentifier: "Detail_Update_View") as! Detail_Update_View 

let nav2 = UINavigationController.init (rootViewController: DetailView) 
self.window?.rootViewController? .present (nav2, animated: true, completion: nil) 

這是從AppDelegate中的FUNC open url調用。

當您單擊小部件中的按鈕時,最初會調用viewB。 再次打開窗口小部件並按下按鈕 的頁面被稱爲但是信息不會改變,以下錯誤將顯示

的errorMessage


Warning: Attempt to present <UINavigationController: 0x101a1b600> on <SWRevealViewController: 0x101820c00> whose view is not the window hierarchy! 

如果你犯了一個首先調用小部件,關閉viewB屏幕(轉到viewA),然後單擊小部件中的按鈕以使其工作。

請幫助我..

+0

那麼你就需要設置初始視圖 - 控制在故事板。 – KKRocks

+0

試試這個:http://stackoverflow.com/a/40304837/3901620 – KKRocks

+0

@KKRocks謝謝你的回覆。這看起來像工作!但是..如果我嘗試3次,我必須按回退按鈕3次才能返回到每個頁面。有沒有辦法一次去viewA? –

回答

0
let mainStoryboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil) 
    let DetailView: Detail_Update_View = mainStoryboard.instantiateViewController(withIdentifier: "Detail_Update_View") as! Detail_Update_View 

    let nav2 = UINavigationController.init (rootViewController: DetailView) 
    let appDelegate = UIApplication.shared.delegate as! AppDelegate 

    appDelegate.window?.rootViewController?.present (nav2, animated: true, completion: nil) 
+0

謝謝你的回答。但它是一樣的...你的答案的第一個工作很好。但有一個問題,無法返回viewA –

+0

如果你使推控制器的導航控制器比只有你可以彈出它是預設的視圖控制器,你只能解僱這個 –

+0

抱歉..我不明白你的意思.. 。 我該怎麼辦? –

相關問題