Reputation: 3
I have a calendar on my app using JTAppleCalendar 7.0
.
However the delegates for the same are not working. Please refer to the screenshot of my requirement.
Somebody kindly share with me the sample delegate functions.
Below is the screenshot of the outlets to the calendar.
Below is the entire code for 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) {
}
}
Upvotes: 0
Views: 1006
Reputation: 186
You actually forgot to call
delegate
and dataSource
. Please adjust your viewDidLoad() as follow:
override func viewDidLoad() {
super.viewDidLoad()
calendarView.calendarDataSource = self
calendarView.calendarDelegate = self
}
Upvotes: 0