Ios 使用UICollectionView Yalantis/Koloda时,初始卡相同
我正在使用这个库,我能够将我的数据从Firebase显示到卡上。但是,初始卡片(3个默认)都是相同的。然后,一旦我滑动它们,我就可以看到下一个结果。只有当我在卡片上显示CollectionView而不是UIView时,才会出现这种情况 以下是我获取数据的方法:Ios 使用UICollectionView Yalantis/Koloda时,初始卡相同,ios,uicollectionview,koloda,Ios,Uicollectionview,Koloda,我正在使用这个库,我能够将我的数据从Firebase显示到卡上。但是,初始卡片(3个默认)都是相同的。然后,一旦我滑动它们,我就可以看到下一个结果。只有当我在卡片上显示CollectionView而不是UIView时,才会出现这种情况 以下是我获取数据的方法: var person: Person! func fetchUser() { let databaseRef = Database.database().reference(withPath: "users") dat
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中正常工作?确保koloda中的索引(koloda:KolodaView,viewForCardAt index:Int)有效。似乎您对所有图像都使用了一个索引。请确保koloda中的索引(koloda:KolodaView,viewForCardAt index:Int)有效。似乎您对所有图像都使用了一个索引