【发布时间】:2016-12-29 04:38:19
【问题描述】:
我很困惑,因为我正在通过字典定义表格视图中的行内容,但是当我尝试添加它时,它会显示一个错误。
var places = [[String: Any]]()
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
if places.count == 0 {
places.append(["name":"Taj Mahal", "lat": "27.175277", "lon": "78.042128"])
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.textLabel?.text = places[indexPath.row]["name"]
return cell
}
错误在我定义的部分:
cell.textlabel?.text = places[indexPath.row]["name"]
【问题讨论】:
-
试试这个cell.textLabel?.text = places[indexPath.row]["name"] as!字符串