0
我很困惑,因爲我通過字典定義表視圖中的行內容,但是當我嘗試添加它時,它會顯示我錯了。Xcode錯誤:'不能賦值:函數調用返回不可變值'在表視圖
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"]
嘗試thiscell.textLabel?.text = places [indexPath.row] [「name」] as!字符串 –