CollectionKit icon indicating copy to clipboard operation
CollectionKit copied to clipboard

multi-view cast view type error

Open SpectatorNan opened this issue 3 years ago • 0 comments

// 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'

SpectatorNan avatar Mar 16 '21 08:03 SpectatorNan