【问题标题】:Accessing FSCalendar function inside custom cell在自定义单元格中访问 FSCalendar 函数
【发布时间】:2020-06-17 12:00:03
【问题描述】:

我在UICollectionViewCell 中有一个FSCalendar 视图,该视图已连接且功能正常。但是,当在 viewController 的扩展中调用 didSelect 日期函数时,没有任何动作(不调用打印函数)。是否需要将特定引用传递给 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
        }
   }

【问题讨论】:

    标签: ios swift uicollectionview uicollectionviewcell fscalendar


    【解决方案1】:

    cellForItemAt里面添加这一行

    cell.calendarView.delegate = self
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多