首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UICollectionView和RxDataSources中删除的项上没有动画

在UICollectionView和RxDataSources中删除的项上没有动画
EN

Stack Overflow用户
提问于 2016-09-20 16:17:05
回答 1查看 1.6K关注 0票数 1

在遵循文档 of RxDataSources之后,我无法使它工作。

当我单击CollectionViews的一个元素时,它会被移除,正如我的代码所示,但是视图上什么也不会发生,尽管我的sections[0].items上有一个更少的元素。我认为我做了一些错误的绑定数据源与视图,但我无法弄清楚它。

代码语言:javascript
复制
    let dataSource = RxCollectionViewSectionedAnimatedDataSource<SectionOfCategoryMO>()
    private var e1cat = CatMngr.SI.getAlphabeticallyOrderedCategories(type: .e1)

    dataSource.configureCell = { ds, tv, ip, item in
        let cell = tv.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: ip) as! CategoryCollectionViewCell
        cell.categoryName.text = item.identity.string
        cell.categoryName.numberOfLines = 0
        cell.categoryCircle.makeCircle()
        cell.categoryCircle.backgroundColor = self.categoryColors[ip.row]
        
        return cell
    }
    
    dataSource.animationConfiguration = AnimationConfiguration(insertAnimation: .Fade, reloadAnimation: .Fade, deleteAnimation: .Automatic)
    
    var sections = [SectionOfCategoryMO(header: "a", items: e1cat)]
    
    Observable.just(sections)
        .bindTo(myCollection.rx_itemsWithDataSource(dataSource))
        .addDisposableTo(disposeBag)
 
    myCollection.rx_itemSelected.subscribeNext{
        sections[0].items.removeAtIndex($0.row)
    }.addDisposableTo(disposeBag)

视图完全包含所有初始类别,但当我删除其中一个类别时,视图不会刷新。

有人知道发生了什么吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-20 16:51:28

这是因为你的sections Array就是一个ArrayObservable.just(sections)不会仅仅因为修改了rx_itemSelected订阅中的sections而发送另一个元素。您需要将数据源绑定到一个Observable,当事情发生变化时,它实际上会发送新的元素。

类似于:

代码语言:javascript
复制
let initialData = [SectionOfCategoryMO(header: "a", items: e1cat)]
let data = Variable<SectionOfCategoryMO>(initialData)
data.asObservable()
    .bindTo(myCollection.rx_itemsWithDataSource(dataSource))
    .addDisposableTo(disposeBag)

myCollection.rx_itemSelected.subscribeNext {
    let d = data.value
    d[0].items.removeAtIndex($0.row)
    data.value = d
}.addDisposableTo(disposeBag)

然而,无论如何,我会推荐一个更健壮的解决方案。用这个例子。

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

https://stackoverflow.com/questions/39599127

复制
相关文章

相似问题

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