即使您單擊其他人的個人資料,也只會顯示當前登錄的用戶。已經問過幾個類似的問題,但我問的是因為語言和環境不同。
為解決該問題,列印了顯示的 ID,但列印的 ID 顯示為不同的用戶。所以也許組態檔控制器有問題,對吧?還是其他地方有問題?
FeedCellDelegate:
protocol FeedCellDelegate: class {
func cell(_ cell: FeedCell, wantsToShowCommentsFor post: Post)
func cell(_ cell: FeedCell, didLike post: Post)
func cell(_ cell: FeedCell, wantsToShowProfileFor uid: String)
}
組態檔控制器:
extension ProfileController {
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return posts.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! ProfileCell
cell.viewModel = PostViewModel(post: posts[indexPath.row])
return cell
}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath) as! ProfileHeader
header.delegate = self
header.viewModel = ProfileHeaderViewModel(user: user)
return header
}
}
進給控制器:
func cell(_ cell: FeedCell, wantsToShowProfileFor uid: String) {
UserService.fetchUser(withUid: uid) { user in
print("id check \(uid)")
let controller = ProfileController(user: user)
self.navigationController?.pushViewController(controller, animated: true)
}
UserService(firebase)
static func fetchUser(withUid uid: String, completion: @escaping(User) -> Void) {
guard let uid = Auth.auth().currentUser?.uid else { return }
Collection_Users.document(uid).getDocument { snapshot, error in
guard let dictionary = snapshot?.data() else { return }
let user = User(dictionary: dictionary)
completion(user)
}
}
饋送單元:
@objc func showUserProfile() {
guard let viewModel = viewModel else { return }
print("check UID : \(viewModel.post.ownerUid)")
delegate?.cell(self, wantsToShowProfileFor: viewModel.post.ownerUid)
}
uj5u.com熱心網友回復:
在您的fetchUser職能中,您總是這樣做:
guard let uid = Auth.auth().currentUser?.uid else { return }
Collection_Users.document(uid).getDocument { snapshot, error in
因此Auth.auth().currentUser?.uid,無論應用程式中發生了什么,您始終可以獲得 的用戶檔案。
如果您想為不同的用戶加載檔案,則必須將點擊的用戶的 UID 傳遞給 ,fetchUser并在對 的呼叫中使用該UID document。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/326246.html
標籤:ios 迅速 谷歌云firestore Firebase 身份验证
下一篇:Mp3音頻無法快速播放
