Skip to content

multi-view cast view type error #158

@SpectatorNan

Description

@SpectatorNan
// course view source
let courseViewSource = ClosureViewSource { (view: StudyCar2CouseView, data: StudyCarCourseListModel, index: Int) in
            view.model = data
               view.tapBtn = { model in
                   self.tapApplyCourse <= model
               }
            }
// coach view source
        let coachViewSource = ClosureViewSource { (view: StudyCar2CoachView, data: ClassCoachModel, index: Int) in
            view.model = data
               view.tapBtn = { model in
                   self.tapApplyCoach <= model
               }
            }
// empty space view source
        let emptyViewSource = ClosureViewSource { (view: UIView, model: StudyCar2ApplyViewTypeProtocol, index: Int) in
            
        }

// size provider
        let sizeSource = { (index: Int, viewType: StudyCar2ApplyViewTypeProtocol, collectionSize: CGSize) -> CGSize in
            if viewType is StudyCarCourseListModel || viewType is ClassCoachModel {
                return CGSize(width: kScreenWid-30.fitR, height: 70.fitR)
            }
            return CGSize(width: 50, height: 50)
          }


        listView.provider = BasicProvider(dataSource: dataSource,
                             viewSource: ComposedViewSource(viewSourceSelector: { (viewType) in
                                if viewType is StudyCarCourseListModel {
                                        return courseViewSource
                                }
                                if viewType is ClassCoachModel {
                                    return coachViewSource
                                }
                                return emptyViewSource
                            }),
                             sizeSource: sizeSource
        )

when change data source

occur cast view type error:
Could not cast value of type 'StudyCar2CouseView' to 'StudyCar2CoachView'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions