0

我有一个包含 2 个集合视图的视图控制器。因此,第一个日历的数据源和委托位于视图控制器扩展中。其次,我正在尝试创建符合数据源和委托协议的类。它给了ViewDidLoad我一个错误Cannot assign value of type 'ExpandableCalendarDataSource.Type' to type 'JTAppleCalendarViewDataSource?'

import UIKit
import JTAppleCalendar

class ExpandableCalendarDataSource: NSObject, JTAppleCalendarViewDataSource {

    let todayDate = Date()
    let formatter = DateFormatter()

    func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
        self.formatter.dateFormat = "yyyy-MM-dd"
        let startDate = formatter.date(from: "2018 01 01")!
        let endDate = formatter.date(from: "2028 01 01")!
        let numberOfRows = 6
        let firstDayOfAWeek:DaysOfWeek = .monday
        calendar.scrollingMode = .stopAtEachSection
        return ConfigurationParameters(startDate: startDate, endDate: endDate, numberOfRows: numberOfRows, firstDayOfWeek: firstDayOfAWeek)
    }


}

extension ExpandableCalendarDataSource: JTAppleCalendarViewDelegate {
    func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {

        let cell = cell as! expandableCalendarDateCell
        cell.dateLabel.text = cellState.text
    }

    func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "dateCell", for: indexPath) as! expandableCalendarDateCell
        self.formatter.dateFormat = "yyyy-MM-dd"
        self.formatter.locale = Calendar.current.locale
        self.formatter.timeZone = Calendar.current.timeZone
        let calendarDate = formatter.string(from: cellState.date)

        return cell
    }
}

viewDidLoad

expandableCalendarCollectionView.calendarDataSource = ExpandableCalendarDataSource.self
expandableCalendarCollectionView.calendarDataSource = ExpandableCalendarDataSource.self
4

1 回答 1

0

只需要制作一个对象

let dataSource = ExpandableCalendarDataSource()

override func ViewDidLoad() {
super.viewDidLoad()

expandableCalendarCollectionView.calendarDataSource = dataSource
expandableCalendarCollectionView.ibCalendarDelegate = dataSource
}
于 2019-04-20T19:44:03.253 回答