Ios RxDataSources在数据源内容的每次更改时都会闪烁

Ios RxDataSources在数据源内容的每次更改时都会闪烁,ios,swift,rx-swift,rxdatasources,Ios,Swift,Rx Swift,Rxdatasources,最初,应用程序显示一个部分的UIViewCollection,然后在收到内容后显示新的部分。用户滚动集合,新的部分添加到集合的底部 我使用MVVM,因此在我的ViewModel中,我向内容数组(model.content)添加了一个新部分,然后通知绑定到collectionView.rx.items(dataSource:self.dataSource)的发布者 因此,每次我添加该部分时,集合都在闪烁,所有单元格都在重新加载,这让可怕的用户体验到所有东西都在闪烁、闪烁、图片消失和出现。有没有办法

最初,应用程序显示一个部分的UIViewCollection,然后在收到内容后显示新的部分。用户滚动集合,新的部分添加到集合的底部

我使用MVVM,因此在我的ViewModel中,我向内容数组(model.content)添加了一个新部分,然后通知绑定到collectionView.rx.items(dataSource:self.dataSource)的发布者

因此,每次我添加该部分时,集合都在闪烁,所有单元格都在重新加载,这让可怕的用户体验到所有东西都在闪烁、闪烁、图片消失和出现。有没有办法不重新加载所有集合,只重新加载差异。我认为默认情况下它应该是这样工作的。也许通知行为主体的方法是错误的想法

我还尝试使用RxtableViewSectionAndAnimatedDataSource,但通过这种方式,所有内容都将消失,并在添加每个新分区后将用户移动到集合视图的最顶端

如果我只在底部添加了一个部分,那么为什么要重新加载所有集合?如何防止

typealias ContentDataSource = RxCollectionViewSectionedReloadDataSource<ContentSection>

class ContentViewController: BaseViewController<ContentViewModel> {

    func setupBindings() {
         viewModel?.sectionItemsSubject
                .bind(to: collectionView.rx.items(dataSource: self.dataSource))
                .disposed(by: self.disposeBag)
    }
}


class ContentViewModel: BaseViewModel<ContentModel> {

    lazy var sectionItemsSubject = BehaviorSubject<[ContentSection]>(value: model.content)

    func updateGeneratedSection(_ section: ContentSection) {
        model.content.append(item)
        sectionItemsSubject.onNext(self.model.content)
    }
}

struct ContentModel {
  
    var content: [ContentSection] = []
}

您的模型可能不符合正确需要的协议,并且差异检查器无法识别相同的单元模型,因此它会再次呈现整个集合视图。 请参阅以下相关文档:

''' 支持扩展项目和节结构 只需使用IdentifiableTypeequalable扩展您的项目,并使用AnimatableSectionModelType扩展您的部分 '''


此外,您可以按照这个示例进行操作-。

CloudBalling的答案是正确的。您的ContentSection类型错误。。。试试这个:

typealias ContentSection = AnimatableSectionModel<ContentSectionModel, ItemCellModel>

struct ContentSectionModel: IdentifiableType {
    var identity: String
    var order: Int
}

struct ItemCellModel: IdentifiableType, Equatable {
    let identity: String
    let img: String
}
typealias ContentSection=AnimatableSectionModel
结构ContentSectionModel:IdentifiableType{
变量标识:字符串
变量顺序:Int
}
struct ItemCellModel:可标识类型,可等式{
let标识:字符串
让img:String
}

请发布您对
ContentSection
@DanielT的定义。更新
typealias ContentSection = AnimatableSectionModel<ContentSectionModel, ItemCellModel>

struct ContentSectionModel: IdentifiableType {
    var identity: String
    var order: Int
}

struct ItemCellModel: IdentifiableType, Equatable {
    let identity: String
    let img: String
}