ios - 我想使用 JTAppleCalender 库显示一个简单的日历,但它显示的是一个空屏幕
问题描述
import UIKit
import JTAppleCalendar
class ViewController: UIViewController, JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource {
let formatter = DateFormatter()
override func viewDidLoad() {
super.viewDidLoad()
}
func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
let myCustomCell = cell as! JTCustomCell
sharedFunctionToConfigureCell(myCustomCell: myCustomCell, cellState: cellState, date: date)
}
func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "JTCustom", for: indexPath) as! JTCustomCell
self.calendar(calendar, willDisplay: cell, forItemAt: date, cellState: cellState, indexPath: indexPath)
cell.lblDate.text = cellState.text
return cell
}
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: "2019 02 02 ")!
let endDate = formatter.date(from: "2020 01 01")!
let paramaters = ConfigurationParameters(startDate: startDate, endDate: endDate)
return paramaters
}
func sharedFunctionToConfigureCell(myCustomCell: JTCustomCell, cellState: CellState, date: Date) {
myCustomCell.lblDate.text = cellState.text
}
}
//ref: JTAppleCalenderLibray 7.1.6
解决方案
确保在 Identity Inspector 中将集合类设置为 JTAppleCalendarView 并设置委托 ibCalendarDataSource 和 ibCalendarDelegate
如果您的日历仍然显示为空白,请在 viewDidLayoutSubviews() 中重新加载
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
calendarView.reloadData()
}
推荐阅读
- javascript - 递归地将父节点的标题存储到根
- javascript - 用户无法选中超过 3 个框的条件
- google-chrome - 如何编辑 Google Chrome DevTools 的“覆盖”选项?
- json - 如何将从 API 提取的数据转换为 CSV
- javascript - 如何在网页上提供压缩文件,以便它可以由函数提取并由库使用?
- javascript - 单击时导航不会转换为全屏
- java - 将 ui 版本更新到 3.3.0 后 FirebaseFirebaseRecyclerAdapter 错误
- excel - 如何在 Excel 宏中指定范围以根据列中的数据将表格导出到多个 CSV 文件
- linux-kernel - 我可以在不从引导加载程序传递单独的 DTB 的情况下引导 linux 内核吗?
- django - Django - 我如何让 id 转到下一个可用的号码?(在应用程序之外添加记录)