gpt4 book ai didi

ios - JTAppleCalendar 代表不适用于 Swift

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

我的应用程序上有一个使用 JTAppleCalendar 7.0 的日历。

但是,同样的代表没有工作。请引用我的需求截图。

请有人与我分享示例委托(delegate)函数。

下面是日历中各门店的截图。

Outlets to the calendar

下面是日历的完整代码。

import UIKit
import JTAppleCalendar

class CalendarViewController: UIViewController, JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource {



@IBOutlet weak var calendarView: JTAppleCalendarView!
let formatter = DateFormatter()

override func viewDidLoad() {
super.viewDidLoad()

}

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {

formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale

let startDate = formatter.date(from: "2018 08 10")!
let endDate = formatter.date(from: "2018 10 10")!

let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate)
return parameters

}

func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
let dateCell = cell as! DateCell
dateCell.dateLabel.text = cellState.text
}


func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {

if let cell = calendarView.dequeueReusableJTAppleCell(withReuseIdentifier: "dateCell", for: indexPath) as? DateCell {
cell.dateLabel.text = cellState.text
cell.configure(date: cellState.text)
return cell
}
return DateCell()
}


func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell, cellState: CellState) {
guard let validCell = cell as? DateCell else { return }
validCell.contentView.backgroundColor = UIColor.black

}


func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleCell, cellState: CellState) {

}

}

最佳答案

enter image description here您实际上忘记调用 delegatedataSource。请调整您的 viewDidLoad() 如下:

override func viewDidLoad() {
super.viewDidLoad()

calendarView.calendarDataSource = self
calendarView.calendarDelegate = self

}

enter image description here

关于ios - JTAppleCalendar 代表不适用于 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51813360/

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