【发布时间】:2019-11-10 19:22:58
【问题描述】:
所以目前我正在为大学做一个 Swift 项目。它有一个应该有 10 个单元格的 TableView,因为我的数据数组有 10 个索引。我能够设置应用程序,除了在 10 个条目后,整个数据集重复,从第一个条目到最后一个条目...This is what the problem looks like.,一切正常。 (TableData 是保存单元格数据的数组)
override func numberOfSections(in tableView: UITableView) -> Int {
return tableData.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath)
let mapLocation = tableData[indexPath.row]
cell.textLabel?.text = mapLocation.name
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectedLocation = tableData[indexPath.row]
performSegue(withIdentifier: "fromTableToMap", sender: selectedLocation)
}
【问题讨论】:
-
您可能希望返回
1作为部分的数量。
标签: ios swift cocoa-touch