如何使用 JTAppleCalendar 将 2 个日历合二为一 ViewController

How to make 2 calendars in one ViewController using JTAppleCalendar

我有一个包含 2 个集合视图的视图控制器。因此,第一个日历的数据源和委托位于视图控制器扩展中。其次,我正在尝试使 class 符合数据源和委托协议。在 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

刚好需要做一个对象

let dataSource = ExpandableCalendarDataSource()

override func ViewDidLoad() {
super.viewDidLoad()

expandableCalendarCollectionView.calendarDataSource = dataSource
expandableCalendarCollectionView.ibCalendarDelegate = dataSource
}