【发布时间】:2018-02-12 14:12:37
【问题描述】:
我有 2 个 coredata 数组。一个有 3 个元素,另一个也有 3 个元素。现在我想在我的表格视图中加载这两个数组。所以我的表格视图中总共有 6 行。
我已经做到了这样......
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let totalCount = (customerDetails.count) + (customerDetails2.count)
return totalCount
}
我尝试在cellForRowAt...中加载这两个数组的数据
let customers = customerDetails[indexPath.row] //CRASHES HERE
for i in 0..<(customerDetails.count) {
cell.nameLabel.text = customers.fname
if i == customerDetails.count {
break
}
}
let customers2 = customerDetails2[indexPath.row]
for i in 0..<(customerDetails2.count) {
cell.nameLabel.text = customers2.fname
if i == customerDetails2.count {
break
}
}
但它在提到Index out of range 的行处崩溃,可能是因为customerDetails 只有 3 行,而加载的单元格总数为 6。
在这种情况下可以做什么..?
【问题讨论】:
标签: ios swift uitableview core-data