gpt4 book ai didi

ios - 我传递的变量不会仅获取视频用户 ID 和个人资料图像 (Swift 3)

转载 作者:行者123 更新时间:2023-11-28 15:21:00 25 4
gpt4 key购买 nike

我传递的变量是一个用户。用户通过了,但是当我通过 uid 时它只显示用户名和个人资料图片。当我通过 uid 时,用户名、个人资料图片和视频应该通过。我不知道为什么它没有收到视频。它只显示当前用户(已登录的用户)的视频。

Here's what I mean when I say it only shows current users videos

Here's the current user that's logged in

How the database looks

为了更好的理解下面的代码:

用户搜索 Controller :

class UserSearchController: UICollectionViewController, UICollectionViewDelegateFlowLayout,UISearchBarDelegate, UISearchDisplayDelegate, GetUserSearchControllerDelegate {

let searchUsersCV: SearchUsersCV = {
let screenHeight = UIScreen.main.bounds.height
let screenWidth = UIScreen.main.bounds.width
let cv = SearchUsersCV(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight))
cv.bringSubview(toFront: cv)
cv.collectionView.register(UserSearchCVCell.self, forCellWithReuseIdentifier: "cellId")

return cv
}()

func searchControllerDidSelect(passedUser: User) {
self.searchBar.isHidden = true
searchBar.resignFirstResponder()

let userProfileController = UserProfileController(collectionViewLayout: UICollectionViewFlowLayout())

userProfileController.userId = passedUser.uid

(searchUsersCV.next as? UIViewController)?.navigationController?.pushViewController(userProfileController, animated: true)

self.navigationController?.pushViewController(userProfileController, animated: true)
}

用户搜索简历:

protocol GetUserSearchControllerDelegate {
func searchControllerDidSelect(passedUser: User)
}

class SearchUsersCV: UIView, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,UISearchBarDelegate {

var delegate: GetUserSearchControllerDelegate?

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.keyboardDismissMode = .onDrag
let user = filteredUsers[indexPath.item]

delegate?.searchControllerDidSelect(passedUser: user)

}

用户配置文件 Controller :

class UserProfileController: UICollectionViewController, UICollectionViewDelegateFlowLayout {

let cellId = "cellId"
var userId: String?

var user: User?

fileprivate func fetchUser() {
let uid = userId ?? FIRAuth.auth()?.currentUser?.uid ?? ""

FIRDatabase.fetchUserWithUid(uid: uid) { (user) in
self.user = user

self.navigationItem.title = self.user?.username

self.collectionView?.reloadData()

}
}

如果您还有任何问题,请告诉我。

最佳答案

在这里我尝试了代码以获得预期的结果。我为您的 userprofileController 做了这个

1) 创建如下两个数组

var videoUrlArray = [String]()
var thumbnailUrlArray = [String]()

2) 使用以下代码不要替换 .评论你的代码并在那里使用我的代码

fileprivate func fetchOrderedPosts() {

let ref = FIRDatabase.database().reference().child("posts").child(currentUserID)

ref.queryOrdered(byChild: "creationDate").observe(.value, with: { (snapshot) in

let dict = snapshot.value as! [String:AnyObject]
print(dict)


let dictValues = [AnyObject](dict.values)
print(dictValues)

for key in dictValues{

let imageUrl = key["videoUrl"] as! String
let imageThumbnail = key["thumbnailUrl"] as! String

self.videoUrlArray.append(imageUrl)
self.thumbnailUrlArray.append(imageThumbnail)

}

self.getResults()
})
}

func getResults(){

print("Thumbnail array : \(self.thumbnailUrlArray)")
print("videoUrlArray : \(self.videoUrlArray)")

self.collectionView?.reloadData()
}

3) 控制台输出结果

enter image description here

现在您可能需要根据从这两个数组接收到的内容来配置单元格。希望对您有所帮助 :) 如果您仍然遇到此代码实现的任何问题,请告诉我

关于ios - 我传递的变量不会仅获取视频用户 ID 和个人资料图像 (Swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46010414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com