【发布时间】:2017-08-02 20:17:27
【问题描述】:
我正在从 JSon 数组创建一个表格列表视图。但我无法根据 indexPath 显示数组名称。我试过 indexOf 但它不可用。
假设在第 1 行,它将显示“Testing”,在第 2 行,它将显示“Yeeea”。我是 swift 新手,被困在这里.. 通常这应该很简单:(
tt_array 已定义
var tt_array: Array<Any>
ViewDidLoad 中的某处
self.tt_array = jsonObj["get_array_list"] as! Array
在我们的 tt_array - print(tt_array)
[{
"array_name" = Testing;
ourid = 4;
total = 2;
}, {
"array_name" = Yeeea;
ourid = 7;
total = 1;
}]
在我们的 cellForRowAt 中
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
var listthis = self.tt_array[indexPath] **error here**
var array_name = listthis['array_name']
cell.textLabel?.text = "TEST"
// Configure the cell...
return cell
}
错误提示:无法使用“IndexPath”类型的索引为“Array”类型的值下标
【问题讨论】:
-
你在 tableview 中得到了什么。?
-
我在上面更新了:错误说:无法使用索引类型为“IndexPath”的下标类型为“Array
”的值 -
嗨一般来说,我们将只使用 indexPath.row。请问self.tt_array[indexPath.row]
标签: xcode uitableview