【发布时间】:2021-12-06 07:48:54
【问题描述】:
即使您点击其他人的个人资料,也只会显示当前登录的用户。有人问过一些类似的问题,但 我问是因为语言和环境不同。
为解决问题,打印显示的 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)
}
}
FeedCell:
@objc func showUserProfile() {
guard let viewModel = viewModel else { return }
print("check UID : \(viewModel.post.ownerUid)")
delegate?.cell(self, wantsToShowProfileFor: viewModel.post.ownerUid)
}
【问题讨论】:
标签: ios swift google-cloud-firestore firebase-authentication