我有一个Firebase数据库,我使用的是FirebaseUI
iOS。该数据库包含我想用来填充UICollectionView的信息:
下面是我的ViewController代码,当前正在生成错误“无法分配FUICollectionViewDataSource类型的值”:
import UIKit
import FirebaseDatabase
import FirebaseDatabaseUI
private let reuseIdentifier = "PollCell"
class TrendingViewController: UICollectionViewController {
var ref: FIRDatabaseReference!
var dataSource: FUITableViewDataSource!
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Register cell classes
self.dataSource = self.collectionView?.bind(to: self.ref) { collectionView, indexPath, snap in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
/* populate cell */
return cell
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
基本上,我希望使用Firebase中的数据填充客户单元格,它将是多个Labels
和ImageView
。这是我创建的自定义单元格:
import UIKit
class PollCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
for: indexPath) as! PollCell
return cell
}
}
任何帮助都将受到赞赏,因为我无法理解如何基本