【问题标题】:Video feed has every video become the same as the most recent upload when using firebase to populate tableview使用 firebase 填充 tableview 时,视频提要使每个视频都与最近上传的视频相同
【发布时间】:2016-12-31 21:19:25
【问题描述】:

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

谁能帮我找出问题所在?使用 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)


            }

    }


}

}

【问题讨论】:

    标签: swift uitableview video firebase firebase-realtime-database


    【解决方案1】:

    您的火基 for 循环没有迭代该值。

    【讨论】:

    • 谢谢你能帮忙详细介绍一下吗?我的快照当前打印该特定值
    • 您的循环只是遍历返回的整个快照。仅仅因为你正在循环它,它被返回并不意味着它实际上已经设置好了。那么你在哪里设置它 if let postDict...
    猜你喜欢
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 2020-09-08
    • 1970-01-01
    • 2020-12-19
    • 2010-10-21
    相关资源
    最近更新 更多