如何从View Controller隔离到TableViewCell

时间:2018-12-09 15:04:37

标签: ios swift segue

如果当前用户在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 :(得分:0)

你想念

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

您需要进行转换的任何地方