gpt4 book ai didi

ios - 如何从 Viewcontroller 转到 UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 07:34:14 25 4
gpt4 key购买 nike

如果当前用户在 ConversationViewcontroller 中选择了任何对话,我想显示与所选用户的聊天。

这次,我的解决方案看起来像那样,但它不起作用:

ConversationViewController 中的通知设置 我在自定义中调用它并在 viewDidLoad 中调用它:

     func customization()  {
self.navigationController?.interactivePopGestureRecognizer?.delegate = nil
// notification setup
NotificationCenter.default.addObserver(self, selector: #selector(pushToUserMesssages(notification:)), name: NSNotification.Name(rawValue: "showUserMessages"), object: nil)
}

显示给定用户的 ChatViewController:

@objc func pushToUserMesssages(notification: NSNotification) {
if let user = notification.userInfo?["user"] as? UserModel {
self.selectedUser = user
self.performSegue(withIdentifier: "segue", sender: self)
}
}

ConversationViewController 中准备 segue:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segue" {
let vc = segue.destination as! ChatViewController
vc.currentUser = self.selectedUser
}
}

在 TableView 中执行 Segue:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if self.items.count > 0 {
self.selectedUser = self.items[indexPath.row].user
self.performSegue(withIdentifier: "segue", sender: self)
}
}

但如果我点击我想打开的聊天,则没有任何效果。预先感谢您的帮助!

最佳答案

你错过了

 NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showUserMessages"), object: nil, userInfo: ["user":user])

无论何时你需要进行转换

关于ios - 如何从 Viewcontroller 转到 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53693626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com