2017-08-06 47 views
1
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    dismiss(animated: true) { 
     let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ChatPage") 
     self.present(viewController, animated: true, completion: nil) 

     print("111") 

    } 
} 

得到錯誤而解僱一個視圖控制器和移動到另一個視圖 - 控制由completionblock
請幫我解決這個問題,我提到的網站,但我仍卡在這裏了。MessagePeopleTableViewController:0x7fb47dd44f80>誰的觀點是不是在窗口層次

+0

看到這個例子https://stackoverflow.com/questions/26022756/warning-attempt-to-present-on-whose-view-is-not-in-the-window-hierarchy-s –

回答

1

看來,您將要呈現已經被解僱的當前控制器的「ChatPage」控制器。我認爲這是原因。

如果您當前的控制器是模態,你可以嘗試這樣的事:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
      dismiss(animated: true) { 

     let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ChatPage")  

     //get access to presenting parent controller 
     self.presentingViewController.present(viewController, animated: true, completion: nil) 

     print("111") 

    } 
} 

或保存父控制器比如在電流控制器,但是這是不好的代碼實際上。

如果這不起作用,另一種方法是使用委託,它將調用父控制器中的某種方法來呈現某些內容。這意味着你應該從控制器調用self.present(viewController,animated:true,completion:nil),該控制器應該提供一個新的控制器(在你的情況下,它是父控制器,我猜),但不是來自將被解僱的控制器

相關問題