我想创建一个segue,通过当前帖子创建者的给定用户ID引导当前用户与vc聊天:
我现在的搜寻:
var user: User?
let chatLogController = ChatLogController(collectionViewLayout: UICollectionViewFlowLayout())
chatLogController.user = user
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationController?.pushViewController(chatLogController, animated: true)
}
ChatLogController.user:
var user: User? {
didSet {
navigationItem.title = user?.name
observeMessages()
}
}
和userClass:
class User: NSObject {
var id: String?
var name: String?
var email: String?
var profileImageUrl: String?
init(dictionary: [String: AnyObject]) {
self.id = dictionary["id"] as? String
self.name = dictionary["name"] as? String
self.email = dictionary["email"] as? String
self.profileImageUrl = dictionary["profileImageUrl"] as? String
}
}
我现在想要拥有的是,segue直接进入特定用户的chatLogController 我知道我需要连接要连接的用户的uid,我也将此属性保存在
下var jobCreatorID: String?
但是我需要更改代码多远才能使其正常工作?
答案 0 :(得分:0)
您应该更改此
var user: User?
因为您要在此将此用户设置为nextviewController
let chatLogController = ChatLogController(collectionViewLayout: UICollectionViewFlowLayout())
chatLogController.user = user
但是此用户是一个avobe声明为用户吗?所以不是用户实例。如果此类具有用户对象,则您应该将该用户
chatLogController.user = self.user
,然后在您的ChatLogController viewDidLoad
中设置标题并获取用户ID,如下所示:
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = self.user
}
因此从该用户那里您获得了ID。