我正在使用这个库,并且能够将 Firebase 中的数据显示到卡片上。但是初始卡(默认为 3 个)都是相同的。然后,一旦我滑动它们,我就可以看到下一个结果。这似乎只有当我在卡片上显示 CollectionView 而不仅仅是 UIView 时才会出现这种情况。
这是我获取数据的方式:
var person: Person!
func fetchUser() {
let databaseRef = Database.database().reference(withPath: "users")
databaseRef.observeSingleEvent(of: DataEventType.value, with: { (snapshot) in
for child in snapshot.children {
guard let snapshot = child as? DataSnapshot else { continue }
let person = Person(from: snapshot)
self.person = person
PersonManager.shared.addPerson(person)
}
self.kolodaView.reloadData()
})
}
这是我将数据分配给单元格的方式:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCell
let person = PersonManager.shared.persons[indexPath.row]
cell.nameLabel.text = person.firstName
return cell
}
PersonManager
是一个处理Person
对象并具有append()
andremoveAll()
功能的单例。
这是我的结果:
有没有人让它与 tableView 或 collectionView 一起正常工作?