Giter Site home page Giter Site logo

Comments (3)

gkuhlmann14 avatar gkuhlmann14 commented on May 13, 2024

Hi @lingzlu have you taken a look at using a datasource? Something like:
let dataSource = RxCollectionViewSectionedReloadDataSource<YourCustomSectionModel>
There's a pretty good example in the examples on it.
You could then do the same kind of thing from the examples:

 func skinTableViewDataSource(dataSource: RxCollectionViewSectionedReloadDataSource<YourCustomSectionModel>) { dataSource.configureCell = { (dataSource, table, idxPath, item) in 
    switch dataSource.itemAtIndexPath(idxPath) { 
      case RegularCell:
        let cell =  collectionView.dequeueReusableCell(withReuseIdentifier: "RegularCell", for: indexPath) as! RegularCell
        // configure regular cell 
        return cell
       case SepcialCell:
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SpecialCell", for: indexPath) as! SpecialCell
    // this cell has different layout with no SectionModel item, configureCell does not get called
      return cell

Then in your viewDidLoad you'll want to have some sort of observable of (regular) [SectionItem] that maps to [YourCustomSectionModel] which you would bind to collectionView.rx_itemsWithDataSource(dataSource)

.map{ regularSectionItems -> [YourCustomSectionModel] in 
  let specialCell = SectionItem.SpecialSectionItem()
  let specialSection = YourCustomSectionModel.SpecialSection(title: "Special", items: [specialCell]) 
  let regularSection = YourCustomSectionModel.RegularSection(title: "Regular", items: regularSectionItems) 
  return [regularSection, specialSection]} 
.bindTo(collectionView.rx_itemsWithDataSource(dataSource)) 
.addDisposableTo(disposeBag) 

Give that a shot

from rxdatasources.

lingzlu avatar lingzlu commented on May 13, 2024

thank gkuhlmann14! I model the example on MultipleSectionModelViewController.swift, and got something working, only problem is that I had to give SectionModel for special cell a dummy item to trigger the configureCell.

from rxdatasources.

kzaher avatar kzaher commented on May 13, 2024

This looks resolved.

from rxdatasources.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.