首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用UICollectionView Yalantis/Koloda时,初始卡是相同的

使用UICollectionView Yalantis/Koloda时,初始卡是相同的
EN

Stack Overflow用户
提问于 2017-11-22 08:29:10
回答 1查看 220关注 0票数 1

我正在使用这个库,并且我能够将我的数据从Firebase显示到卡上。但是,初始卡片(3张默认卡片)都是相同的。然后,一旦我滑动它们,我就可以看到下一个结果。这似乎只有当我在卡上显示CollectionView而不仅仅是UIView时才会出现这种情况。

下面是我获取数据的方法:

代码语言:javascript
复制
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()

    })
}

下面是我将数据分配给单元格的方式:

代码语言:javascript
复制
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上正常工作?

EN

回答 1

Stack Overflow用户

发布于 2018-07-06 23:12:16

确保koloda中的索引(_ koloda: KolodaView,viewForCardAt索引: Int)有效。您似乎对所有图像都使用了一个索引。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47424974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档