我正在使用这个库,并且我能够将我的数据从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()和removeAll()函数。
这是我的结果:

有没有人能让它在tableView或collectionView上正常工作?
发布于 2018-07-06 23:12:16
确保koloda中的索引(_ koloda: KolodaView,viewForCardAt索引: Int)有效。您似乎对所有图像都使用了一个索引。
https://stackoverflow.com/questions/47424974
复制相似问题