我有这个数组:
var cars : NSArray = [
["name":"Dayatona", "marca":"Dodge","ano":"1969"],["name":"Viper", "marca":"Dodge","ano":"1969"],["name":"F344", "marca":"Dodge","ano":"1969"],["name":"Dayatona", "marca":"Dodge","ano":"1969"],["name":"Cobra", "marca":"Dodge","ano":"1969"],["name":"Dayatona", "marca":"Dodge","ano":"1969"],["name":"GT500", "marca":"Dodge","ano":"1969"]
]
我需要在这里获得每个项目的“名称”:
func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath){
cell.textLabel?.text = cars["name"]
}
答案 0 :(得分:1)
cars[indexPath.row].valueForKey(“name”)
您将字典存储在数组中。
cars[indexPath.row]
用于获取数组中与UITableView
.valueForKey(“name”)
用于从字典中获取name
编辑:
var cars : NSArray = [
["name":"Dayatona", "marca":"Dodge","ano":"1969"],["name":"Viper", "marca":"Dodge","ano":"1969"],["name":"F344", "marca":"Dodge","ano":"1969"],["name":"Dayatona", "marca":"Dodge","ano":"1969"],["name":"Cobra", "marca":"Dodge","ano":"1969"],["name":"Dayatona", "marca":"Dodge","ano":"1969"],["name":"GT500", "marca":"Dodge","ano":"1969"]
]
func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath){
println(cars[indexPath.row].valueForKey("name"))
}
configureCell(UITableViewCell(), atIndexPath: NSIndexPath(forRow: 1, inSection: 1))
用于测试(Swift 1.2)并确认可以正常工作