作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果当前用户在 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/
我是一名优秀的程序员,十分优秀!