作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试用要播放的视频填充我的 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/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!