首页 文章

如何从View Controller查看到TableViewCell

提问于
浏览
1

如果当前用户在 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)
    }
}

但如果我点击我要打开的聊天,没有任何作用 . 在此先感谢您的帮助!

1 回答

  • 0

    你想念

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

    你需要在哪里进行过渡

相关问题