【发布时间】:2017-11-02 04:06:50
【问题描述】:
我想点击基于ID的行,
所以我声明了一个数组来存储 ID:
var idenArr = [String]()
在 didSelectRowAt 索引路径上:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var cell = tableView.dequeueReusableCell(withIdentifier: "myOrderTableViewCell", for: indexPath as IndexPath) as! MyOrderTableViewCell
cell = idenArr[indexPath.row] `<-- Here show me this error "Cannot assign value of type 'String' to type 'MyOrderTableViewCell'"`
}
【问题讨论】:
-
||请阅读有关表格视图的信息。以上 2 行中还有很多其他问题,而不仅仅是您指出的问题。为什么您需要在 didSelectRowAt 中对一个单元格进行双端队列,这是 cellForRowAt 的工作?您正在分配字符串值以键入 MyOrderTableViewCelll。
-
在错误行中,您的代码实际上是在尝试将 id 的值分配给 Cell。这就是它来的原因。
-
将
cell =更改为cell.textLabel.text = -
永远不要在
cellForRowAt之外打电话给tableView.dequeueReusableCell。
标签: ios swift didselectrowatindexpath