我在UITableView中遇到索引超出范围问题。 下面是我的代码:致命错误:索引超出范围swift
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
//== Teble: number of tables ==============================//
func numberOfSections(in tableView: UITableView) -> Int {
return headerTitleArray.count
}
//== Teble rows: number of rows ==============================//
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellTitleMultiArray.count
}
//== Teble rows: data for each row ==============================//
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomTableViewCell
let text = cellTitleMultiArray[indexPath.section][indexPath.row]
cell.titleLabel.text = text
return cell
}
}
我试图解决这个问题,但不能。请请帮我解决这个问题....
这是正确的'return cellTitleMultiArray.count'?听起来像你想要的。我认为它应该是'return cellTitleMultiArray [section] .count' –
'return cellTitleMultiArray.count' =>'return cellTitleMultiArray [indexPath.section] .count' – Larme
我试过了cellTitleMultiArray [section] .count,但它崩溃了 –