ReactiveX / RxSwift

Reactive Programming in Swift
MIT License
24.37k stars 4.17k forks source link

How to according to the different datasource in one tableview show different cell,and one have a collectionView. and one collectionView have different collectionViewCell #1520

Closed YunyueLin closed 6 years ago

YunyueLin commented 6 years ago

:warning: If you don't have something to report in the following format, it will probably be easier and faster to ask in the slack channel first. :warning:

:warning: Please take you time to fill in the fields below. If we aren't provided with this basic information about your issue we probably won't be able to help you and there won't be much we can do except to close the issue :( :warning:

If you still want to report issue, please delete above statements before submitting an issue.

Short description of the issue:

How to according to the different datasource in one tableview show different cell,and one have a collectionView. and one collectionView have different collectionViewCell

Expected outcome:

bind success

What actually happens:

crash

Self contained code example that reproduces the issue:

  Now, my tableViewCell have a func to 
return 'RxCollectionViewSectionedReloadDataSource (
configureCell: { (ds, cv, indexPath, element) in

}'

And at UIViewController's 
func dataSource() -> RxTableViewSectionedReloadDataSource<MultipleSectionModel> {
        return RxTableViewSectionedReloadDataSource<MultipleSectionModel>(
            configureCell: { (dataSource, table, indexPath, _) in
                switch dataSource[indexPath] {
                case let .merchant(merchant):
                   ...
                case let .topic(topic):
                    let cell = table.dequeueReusableCell(withIdentifier: TopicInfoCell.idStr()) as! TopicInfoCell
                    cell.name.text = "   " + topic.name + "   "
                    IVManager.dd_FastSetImageWithUrlStr(imageView: cell.mainImg, URLStr: topic.image)
                    cell.num.text = topic.total
                    cell.content.text = topic.introduction

                    var itemAry : [SectionItem] = []
                    for fabricModel in topic.cloths{

                        itemAry.append(.fabric(fabricModel: fabricModel))
                    }

                    Observable.just([MultipleSectionModel.FabricSection(title: "String", items: itemAry)])
                        .bind(to: cell.collectionView.rx.items(dataSource: cell.dataSource()))
                        .disposed(by: self.disposeBag)

                    return cell
                case let .fabric(fabricModel):
                   ...
                default:
                    return UITableViewCell()

                }
        }
        )
    }

// If we can't get a self contained code example that reproduces the issue, there is a big chance we won't be able
// to help you because there is not much we can do.
//
// `Self contained code example` means:
//
// * that we should be able to just run the provided code without changing it.
// * that it will reproduce the issue upon running

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

4.0.0

Platform/Environment

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

Xcode version:

  9.1

:warning: Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. :warning:

Installation method:

I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)

Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)

abdulowork commented 6 years ago

@YunyueLin Take a look at this answer.