是否可以将两个值分配给UITableView中的单元格?Swift将两个值分配给UITableViewCell
我有一个结构类似的JSON文件:
{
"band": [
"Name": "The Kooks",
"id": "1258"
]
}
我可以得到标签在单元格中显示并把它传递到一个新的视图控制器,但我怎么也分配ID,以便我也可以传递?
我是新来的快,所以请不要吃我。
编辑1:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
cell.textLabel?.text = self.items[indexPath.row]
return cell
}
项目是空的,所以我得到它像这样:
Alamofire.request(.GET, testurl, parameters: ["bandName": bandName])
.responseJSON { response in
switch response.result {
case .Success:
if let value = response.result.value {
let json = JSON(value)
for (_,bands) in json {
for (_,bname) in bands {
let bandName = bname["Name"].stringValue
print(bandName)
self.items.append(bandName)
self.tableView.reloadData()
}
}
}
case .Failure(let error):
print(error)
}
}
请用String (格式:“String%@%@”,变量); –
erm?谨慎解释? – JamesG
您不会将其分配给单元格。您将ID保存在您的模型中,然后通过'prepareForSegue'中的选定单元格的'indexPath'来检索它。 –