gpt4 book ai didi

swift - 使用 firebase 填充 tableview 时,视频源的每个视频都与最近上传的视频相同

转载 作者:行者123 更新时间:2023-11-30 12:47:43 27 4
gpt4 key购买 nike

我正在尝试用要播放的视频填充我的 VideoFeed。但每当我上传新视频时,提要上的每个视频都会变得与上一个相同。

谁能帮我找出问题所在吗?使用 Swift 3。

import UIKit
import Firebase
import AVKit
import AVFoundation


class VideoFeedVC: UIViewController, UITableViewDelegate, UITableViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak var tableView: UITableView!

var post: Post!
var posts = [Post]()
var imagePicker : UIImagePickerController! //Sets imagePicker to type UIImagePickerController

var url: URL! //URL for video
var destination: AVPlayerViewController! //Destination for video

override func viewDidLoad() {
super.viewDidLoad()

tableView.delegate = self
tableView.dataSource = self


imagePicker = UIImagePickerController()

DataService.ds.REF_VIDEOS.observe(.value, with: { (snapshot) in
if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshot {
print("SNAP: \(snap)") //Prints all snapshots
if let postDict = snap.value as? Dictionary<String, AnyObject> {
let id = snap.key
let post = Post(postID: id, postData: postDict)
self.posts.append(post)
}
}
}
self.tableView.reloadData() //Need this
})

}


func numberOfSections(in tableView: UITableView) -> Int {

return 1

}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return posts.count

}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

//return UITableViewCell()

post = posts[indexPath.row]

print(post.videoURL)




if let cell = tableView.dequeueReusableCell(withIdentifier: "videoCell") as? VideoCell {

cell.configureCell(post: post)

return cell

} else {
return VideoCell()
}

}

// This function gets the video to play.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "videoToPlay" {


let destination = segue.destination as! AVPlayerViewController


url = URL(string: post.videoURL)

if let movieURL = url {
destination.player = AVPlayer(url: movieURL)


}

}


}

}

最佳答案

您的火基 for 循环不会迭代该值。

关于swift - 使用 firebase 填充 tableview 时,视频源的每个视频都与最近上传的视频相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41411788/

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