如何在RxSwift中选择CollectionView单元格 [英] How to select CollectionView cell in RxSwift
本文介绍了如何在RxSwift中选择CollectionView单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用RxSwift在集合视图中的特定索引处选择项目.此方法无法正常工作.
I need to select the item at specific index in collection view using RxSwift.This method is not working fine.
collectionView.rx.modelSelected(SearchResult.self).subscribe(onNext:{ menuItem in }).addDisposableTo(disposeBag)
有人可以帮忙吗?
推荐答案
如果要选择项目的indexPath,可以使用以下命令:
If you want the indexPath of item selected you can use the following :
collectionView
.rx
.itemSelected
.subscribe(onNext:{ indexPath in
//your code
}).disposed(by: disposeBag)
,如果要选择模型,则:
and if you want to the model being selected :
collectionView
.rx
.modelSelected(SearchResult.self)
.subscribe(onNext: { (model) in
//Your code
}).disposed(by: disposeBag)
并且您可以结合以上内容,以如下方式获取带有indexPath的modelSelected:
And you can combine the above, to get the modelSelected with their indexPath as follow:
Observable
.zip(
collectionView
.rx
.itemSelected
,collectionView
.rx
.modelSelected(SearchResult.self)
)
.bind{ [unowned self] indexPath, model in
}
.disposed(by: disposeBag)
}
这篇关于如何在RxSwift中选择CollectionView单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文