【发布时间】:2016-02-03 06:47:10
【问题描述】:
这是上一个问题的基础。
我有一个这样定义的数组:
var items = [[String:String]]()
此数据是从 json 文件动态更新的
for (_,bands) in json {
for (_,bname) in bands {
let bnameID = bname["id"].stringValue
let bnameName = bname["Title"].stringValue
let dict = ["id":bnameID,"Title":bnameName]
self.items.append(dict as [String : String])
self.tableView.reloadData()
}
}
这是我打印 items 数组时的输出
[["Title": "The Kooks", "id": "2454"],
["Title": "The Killers", "id": "34518"],
["Title": "Madonna", "id": "9"]]
问题一:
在这个函数中
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { }
如何让单元格标签显示数组“标题”部分中的项目?
问题 2
在这个函数中:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { }
如何从与单击的单元格对应的数组中获取值“id”?例如,如果单击 The Killers 单元格,那么我可以设置一个值为:34518
的变量【问题讨论】:
标签: ios swift uitableview