我在一个UICollectionViewCell
中有一个FScalendar
视图,该视图是连接的和功能的。 但是,当在viewController的扩展中调用didSelect date函数时,什么也不执行(不调用print函数)。 是否需要将特定引用传递给CellForIndexPath才能调用此函数?
分机代码:
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