Home > Software design >  iOS FSCalendar delegate not working when calendar is in tableview cell
iOS FSCalendar delegate not working when calendar is in tableview cell

Time:04-20

i created a cell which contains FSCalendar. I'm registering my cell to table view in my controller but delegate is not working.

My cell is like:

@IBOutlet weak var calendarView: FSCalendar!
@IBOutlet weak var nextMonthButton: UIButton!
@IBOutlet weak var previousMonthButton: UIButton!

In my view controller, i connected tableview's delegate and datasource, registered my cell. However, cell's calendar's delegate methods are not working. What should i do?

func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
}

CodePudding user response:

I think you did not setup the delegate and datasource for the calendarView property. You either have to initialize it under tableViewCell’s awakeFromNib() method or on your controller’s tableView(_:cellForRowAt:) method where you are drawing the cell.

cell.calendarView.delegate = self
cell.calendarView.dataSource = self
  • Related