ios - 'UITableViewCell' 类型的值没有成员 'Job'
问题描述
我试图将数据加载到表格视图中,但出现错误 - 'UITableViewCell' 类型的值没有成员 'Job' & 'UITableViewCell' 类型的值没有成员'DateTime'。Job & DateTime 是我想在表格视图单元格中显示的变量。如何摆脱错误?
// MARK: - UITableViewDataSource
extension CalendarViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return displayName.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
cell.Job.text = displayName[indexPath.row]
cell.DateTime.text = displayDateTime[indexPath.row]
return cell
}
}
解决方案
由于 Job 和 DateTime 不是 UITableviewCell 类的默认成员,您需要将 UITableViewCell 类型转换为您的自定义 tableviewcell 类,如图所示,
// MARK: - UITableViewDataSource
extension CalendarViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! YourTableCellClass
cell.Job.text = displayName[indexPath.row]
cell.DateTime.text = displayDateTime[indexPath.row]
return cell
}
}
推荐阅读
- ocr - Tesseract/gImageReader OCR:旧文本在单词之间缺少空格
- heroku - 失败的heroku前端部署
- c - RLE 实施每隔一段时间就会失败
- android - Activity 结果 API 的 ActivityResultLauncher launch() 方法不仅会调用合约的 createIntent() 方法,还会调用 parseResult()
- numpy - Keras、PyTorch 和 Numpy 中的批量标准化是不同的
- c++ - 为什么这种替换失败会再次产生错误?
- reactjs - 处理在前端 React 表单中将坐标插入到 geojson 的多部分表单
- javascript - 这个带有记忆(JavaScript)的斐波那契程序的运行过程是什么?
- reactjs - 使用 React redux/thunk 和 axios 连接 Firebase(来自 google)
- flutter - 如何通过扩展过滤 build_runner 输入?