在自定义单元格中访问 FSCalendar 函数

Accessing FSCalendar function inside custom cell

我在 UICollectionViewCell 中有一个 FSCalendar 视图,该视图已连接且正常运行。但是,当在 viewController 的扩展中调用 didSelect 日期函数时,不会执行任何操作(不会调用打印函数)。是否需要将特定引用传递给 CellForIndexPath 才能调用此函数?

分机号:[=​​15=]

extension CalendarViewController: FSCalendarDelegate, FSCalendarDataSource {

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

    print("Date selected")
    }
}

自定义单元格:

class ChartCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var calendarView: FSCalendar!

}

CollectionView cellForItemAt 代码:

   func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {


        if indexPath.item == 0 {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "chartCell", for: indexPath) as! ChartCollectionViewCell

            return cell
        }
   }

cellForItemAt里面加上这一行

cell.calendarView.delegate = self