You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift开发报错:This property is defined but not available in this context——TableView无法访问Sqlite数据库模型属性

问题原因及解决方案

错误根源分析

你遇到的这个错误主要来自两处代码问题:

  • 语法错误:在dataTableWord.[indexPath.row].idWord这行里,数组索引的写法多了一个多余的点,正确的数组元素访问应该是dataTableWord[indexPath.row],不需要在数组名和方括号之间加.。
  • 类型不匹配:idWord是Int类型,而UILabel的text属性需要的是String类型,直接赋值会导致类型不兼容,这也是触发该错误提示的核心原因。

修正后的代码

把cellForRowAt方法里的代码改成这样即可解决问题:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "idCell1Main1", for: indexPath) as! TableViewCell
    // 修复数组访问语法,同时将Int类型转为String类型
    cell.cellLabelNumber.text = String(dataTableWord[indexPath.row].idWord)
    return cell
}

小补充:如果dataTableWord数组是空的,TableView会显示空白,你可以提前给数组填充一些测试数据,确保能看到预期的单元格内容~

内容的提问来源于stack exchange,提问作者SwiftLove

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 10:37:39