Ios I';m通过不';t仅获取视频用户Id和配置文件图像(Swift 3)
我传递的变量是一个用户。用户通过,但当我通过uid时,它只显示用户名和配置文件图片。当我传递uid时,用户名、配置文件图像和视频都应该传递。我不知道为什么它没有得到视频。它只显示当前用户(已登录的用户)的视频 以下是更好理解的代码: 用户搜索控制器:Ios I';m通过不';t仅获取视频用户Id和配置文件图像(Swift 3),ios,iphone,swift,xcode,firebase,Ios,Iphone,Swift,Xcode,Firebase,我传递的变量是一个用户。用户通过,但当我通过uid时,它只显示用户名和配置文件图片。当我传递uid时,用户名、配置文件图像和视频都应该传递。我不知道为什么它没有得到视频。它只显示当前用户(已登录的用户)的视频 以下是更好理解的代码: 用户搜索控制器: class UserSearchController: UICollectionViewController, UICollectionViewDelegateFlowLayout,UISearchBarDelegate, UISearchD
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)
}
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()
}
}
UserSearchCV:
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)
}
用户配置文件控制器:
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)
}
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) 控制台的输出结果
现在,您可能需要根据从这两个阵列接收的内容配置单元。。希望对您有所帮助:)并让我知道您是否仍然面临此代码实现的任何问题我可以查看您的数据库结构和用户类吗please@iOSGeek是的,我刚刚编辑了这篇文章@iOSGeek It上传帖子并正确接收,但在查看其他用户时不会接收帖子。它显示的是当前用户的帖子,而不是您是否正在使用posts节点中的处理程序迭代并从UID获取详细信息?您得到的结果是来自节点用户。我不这么认为/可能。我可以解释我的意思,如果我们进入聊天室,最好解释一下@iOSGeek