简体   繁体   English

单击 tableView 单元格时如何推送新的 viewController?

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

I thought that I had this code correct;我以为我的代码是正确的; however, when I run it, I click on the cell and nothing happens.然而,当我运行它时,我点击了单元格,但没有任何反应。 The code that I have to push the view controller is in my didSelectRowAt func.我必须推送视图控制器的代码在我的 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)
}

Can anyone explain what I'm doing wrong here and why a click doesn't show a new ViewController?谁能解释一下我在这里做错了什么以及为什么单击不显示新的 ViewController?

You must try this to solve the problem, if there is any issues else you can ask me你必须尝试这个来解决问题,如果还有其他问题你可以问我

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.

相关问题 如何从xib tableview Cell推送ViewController? - how to push ViewController from xib tableview Cell? 单击该特定单元格时,如何向另一个ViewController显示一个表格视图单元格的数据? - How to show the data of a tableview cell to another viewcontroller when clicking on that particular cell? 轻按单元格时将值推送到新的ViewController - Push the values to new ViewController when a cell is tapped [以编程方式]选择嵌入在 collectionView 单元格中的 tableView 行时推送 viewController - [Programmatically]Push a viewController when selecting tableView row embedded in a collectionView cell 通过单击swift中的TableView单元格转到ViewController - Go to the ViewController by clicking on the TableView cell in swift 当在 Swift 5 中点击 Tableview Row 时,如何使用 Xib(不是 StoryBoards)在 SideMenu Controller 中设置 UINavigationController 以推送新的 ViewController - How to set UINavigationController in SideMenu Controller using Xib (Not StoryBoards) to push new ViewController when Tableview Row Tapped in Swift 5 迅速单击表格视图单元格,打开一个新的TabBarController - Open a new TabBarController on clicking a tableview cell in swift 如何关闭并推送新的ViewController - How to dismiss and push new ViewController 如何在新窗口中推送 ViewController - How to Push ViewController in new window 当使用NSArray中的字符串时,如何将UITextField推送到新的ViewController? - how to have UITextField push to a new ViewController when a string in an NSArray is used?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM