【发布时间】:2018-10-28 18:36:39
【问题描述】:
我在一个单元格中有两个标签,在一个表格视图中有两个数组,我想将每个数组与标签链接
list [ ] 与 la_view 和 list_2 [ ] 与 la_view2 , 在表格视图的一个单元格中也有 la_view 和 la_view2
程序运行时显示Error如图。
var list = [String]()
var list_2 = [String]()
func tableView (_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return list.count + list_2.count
}
func tableView (_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell_1") as! TableView_Cell
print("\(list.count)")
cell.la_view.text = list[indexPath.row]
cell.la_view2.text = list_2[indexPath.row] // eroor here
cell.backgroundColor = UIColor(named: "Defeult")
return cell
}
// This append in arrays
func append(add:Int) {
list.append("\(add)")
list_2.append("\(add)")
let indexPath = IndexPath(row: list.count - 1, section: 0)
let indexPath2 = IndexPath(row: list_2.count - 1, section: 0)
table_View.beginUpdates()
table_View.insertRows(at: [indexPath], with: .automatic)
table_View.insertRows(at: [indexPath2], with: .automatic)
table_View.endUpdates()
}
【问题讨论】:
-
错误是什么?
标签: arrays swift uitableview