簡體   English   中英

單擊 tableView 單元格時如何推送新的 viewController?

[英]How to push a new viewController when clicking on a tableView cell?

我以為我的代碼是正確的; 然而,當我運行它時,我點擊了單元格,但沒有任何反應。 我必須推送視圖控制器的代碼在我的 didSelectRowAt 函數中。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let vc = ChatViewController()
        vc.title = "Jenny Smith"
        vc.navigationItem.largeTitleDisplayMode = .never
        navigationController?.pushViewController(vc, animated: true)
}

誰能解釋一下我在這里做錯了什么以及為什么單擊不顯示新的 ViewController?

你必須嘗試這個來解決問題,如果還有其他問題你可以問我

let VC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ChatViewController") as! ChatViewController
self.navigationController?.pushViewController(VC, animated: false)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM