gpt4 book ai didi

swift - 如何使用 JTAppleCalendar 在一个 ViewController 中制作 2 个日历

转载 作者:行者123 更新时间:2023-11-30 10:45:51 25 4
gpt4 key购买 nike

我有一个包含 2 个 Collection View 的 View Controller 。因此,第一个日历的数据源和委托(delegate)位于 View Controller 扩展中。第二,我试图创建符合数据源和委托(delegate)协议(protocol)的类。在 ViewDidLoad 中,它给了我一个错误 Cannot allocate 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
}

关于swift - 如何使用 JTAppleCalendar 在一个 ViewController 中制作 2 个日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55776757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com