24852

How to select CollectionView cell in 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)

Can anybody help?

Answer1:

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)

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) }

Recommend

  • Can enum member be the size of an array in ANSI-C?
  • Refreshing MutableLiveData of list of items
  • How can I get sizeof a vector::value_type?
  • Design UIView subclass auto layout with custom size in Interface Builder xib file
  • CSStickyHeaderFlowLayout swift
  • Messing UIButton in each UICollectionViewCell in Scrolling Filmstrip
  • deserialize json array to java object using Jackson
  • how to sort elasticsearch results using jest
  • Asynchronous unit test not being called by SenTestCase
  • UIRefreshControl with low height UICollectionView
  • Unable to send a &str between threads because it does not live long enough
  • http request every x seconds in angular
  • non-conformable arrays when passing numpy array to R via rpy2
  • [Rx.js]when does Zip operator emit error?
  • Creating a Messenger service
  • RS-232 communication using an Arduino Duemilanove and the Cutedigi RS-232 interface
  • NServiceBus - NServiceBus.Host as publisher and WPF app as subscriber. How To?
  • How can I figure out what UITableViewCell I'm clicking on during a search?
  • Ionic2: Unsubscribe Event to Avoid Duplicate Entries?
  • Angular5 Service Worker update(SWUpdate) not detecting on firefox. Working on chrome
  • How can I let users share their location in Bot Framework webchat channel?
  • Adding a model to a Marionette CollectionView's collection doesn't trigger onItemAdd callb
  • Play WS (2.2.1): post/put large request
  • Get data from AJAX - How to
  • Initializer list vs. initialization method
  • Jenkins: How To Build multiple projects from a TFS repository?
  • Spring security and special characters
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Perl system calls when running as another user using sudo
  • Trying to switch camera back to front but getting exception
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • How can I estimate amount of memory left with calling System.gc()?
  • Matrix multiplication with MKL
  • Free memory of cv::Mat loaded using FileStorage API
  • Hits per day in Google Big Query
  • Angular 2 constructor injection vs direct access
  • File not found error Google Drive API
  • Programmatically clearing map cache
  • Converting MP3 duration time