iosswiftxcodeuicollectionviewcelljtapplecalendar

i want to show a simple calender using JTAppleCalender library but it is showing an empty Screen


import UIKit
import JTAppleCalendar
class ViewController: UIViewController, JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource {


    let formatter = DateFormatter()

    override func viewDidLoad() {
        super.viewDidLoad()

    }



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

        let myCustomCell = cell as! JTCustomCell
        sharedFunctionToConfigureCell(myCustomCell: myCustomCell, cellState: cellState, date: date)

    }

    func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "JTCustom", for: indexPath) as! JTCustomCell
        self.calendar(calendar, willDisplay: cell, forItemAt: date, cellState: cellState, indexPath: indexPath)
        cell.lblDate.text = cellState.text

        return cell
    }

    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: "2019 02 02 ")!
        let endDate = formatter.date(from: "2020 01 01")!

        let paramaters = ConfigurationParameters(startDate: startDate, endDate: endDate)
        return paramaters
    }

    func sharedFunctionToConfigureCell(myCustomCell: JTCustomCell, cellState: CellState, date: Date) {
        myCustomCell.lblDate.text = cellState.text

    }


}
//ref: JTAppleCalenderLibray 7.1.6

Solution

  • Make sure you collection class is set to JTAppleCalendarView in Identity Inspector and set the delegate ibCalendarDataSource and ibCalendarDelegate

    If your calendar still appears blank make a reload in viewDidLayoutSubviews()

    override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            calendarView.reloadData()
        }