type'[[string:string]]'?具有
问题描述:
我试图提出从另一屏幕的表格视图信息和我得到这个错误消息没有下标构件:type'[[string:string]]'?具有
类型“[[字符串:字符串]]”?没有下标构件
class TestListViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
let userTest = DataManager.getInstance().getRecord()
let arrayOfDateString = DataManager.getInstance().getArrayOfKeys()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var tableView: UITableView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userTest!.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as UITableViewCell
// cell.textLabel?.text = userTest[indexPath.row] - **here is the problem
cell.detailTextLabel?.text = "Your record"
return cell
}
}
答
改变此密码 -
cell.textLabel?.text = userTest[indexPath.row]
向该代码 -
cell.textLabel?.text = userTest![indexPath.row]
+0
- 我对不起,仍然不好表格视图 – Moran
+0
什么是错误? –
不要使用一个可选为表视图控制器的数据源阵列。这将解决你的问题。和 - 无关 - 不要将“UITableViewCell”转换为“UITableViewCell”。删除'作为UITableViewCell'。 – vadian
@vadian - 你可以给我,你是什么意思? – Moran
声明您的数据源数组为非可选(不带问号)。在填充数据源数组之后,你必须在表视图的某处调用'reloadData()'。 – vadian