0

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

然而,同样的代表没有工作。请参考我的要求截图。

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

以下是日历的网点截图。

出口到日历

下面是日历的完整代码。

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) {

    }

}
4

1 回答 1

0

在此处输入图像描述你实际上忘了打电话delegateand dataSource。请调整您的 viewDidLoad() 如下:

override func viewDidLoad() {
   super.viewDidLoad()

   calendarView.calendarDataSource = self
   calendarView.calendarDelegate = self

}

在此处输入图像描述

于 2018-08-13T17:24:22.110 回答