2016-08-22 3 views
9

하나의 테이블보기에서 여러 사용자 정의 셀을 사용할 수있는 경우 RxSwift에 대한 코드 예제가 있습니까? 예를 들어 두 섹션이 있고 첫 번째 섹션에는 CellWithImage 식별자가있는 10 개의 셀이 있고 두 번째 섹션에는 CellWithVideo 식별자가있는 셀이 10 개 있습니다.여러 사용자 정의 셀 유형이있는 RxSwift 테이블보기

내가 RxSwiftDataSources 사용하여 관리했습니다

답변

3

어떤 도움을 예를 들어, 하나 개의 세포 유형을 사용하는 RxSwiftTableViewExample

감사를 설립 한 모든 tuts 및 코드 예제,

이 허용 당신은 다중 섹션과 함께 사용자 정의 셀을 사용합니다.

+4

결국 코드를 ​​어떻게 구현했는지 공유 할 수 있습니까? – nburk

2

아무도 관심이있는 경우, 여기 내 구현이 있습니다. 게임 목록이있는 앱이 있습니다. 게임이 끝났거나 계속 진행 중인지에 따라 다른 셀을 사용합니다. 여기에 내 코드입니다 : 뷰 모델에서

, 나는 완료/진행중인 것들로 분할, 게임의 목록을 가지고 있고, 내가있는 tableview 내 부분을 바인딩의 ViewController에서 다음 SectionModel

let gameSections = PublishSubject<[SectionModel<String, Game>]>() 
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, Game>>() 

... 

self.games.asObservable().map {[weak self] (games: [Game]) -> [SectionModel<String, Game>] in 
    guard let safeSelf = self else {return []} 
    safeSelf.ongoingGames = games.filter({$0.status != .finished}) 
    safeSelf.finishedGames = games.filter({$0.status == .finished}) 

    return [SectionModel(model: "Ongoing", items: safeSelf.ongoingGames), SectionModel(model: "Finished", items: safeSelf.finishedGames)] 
}.bindTo(gameSections).addDisposableTo(bag) 

에 매핑 , 이렇게 다른 세포를 사용하십시오. indexPath를 사용하여 상태 대신 올바른 셀을 가져올 수 있습니다.

vm.gameSections.asObservable().bindTo(tableView.rx.items(dataSource: vm.dataSource)).addDisposableTo(bag) 
vm.dataSource.configureCell = {[weak self] (ds, tv, ip, item) -> UITableViewCell in 
    if item.status == .finished { 
     let cell = tv.dequeueReusableCell(withIdentifier: "FinishedGameCell", for: ip) as! FinishedGameCell 
     cell.nameLabel.text = item.opponent.shortName 
     return cell 
    } else { 
     let cell = tv.dequeueReusableCell(withIdentifier: "OnGoingGameCell", for: ip) as! OnGoingGameCell 
     cell.titleLabel.text = item.opponent.shortName 
     return cell 
    } 
} 
관련 문제