Index out of range: file
goalguy10 opened this issue · comments
I have a case where I have 3 sections and everything is working perfectly except when one of those sections exceeds 10 rows. I get a Fatal error: Index out of range: file when I scroll to the 10th row.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
print("Count: ", self.contacts.count)
switch indexPath.section{
case 0:
return startingCellHeights[indexPath.row]
case 1:
return contactCellHeights[indexPath.row] //Fatal error: Index out of range: file
default:
return endingCellHeights[indexPath.row]
}
}
@goalguy10 Hey your sources are not informative enough to make an unambiguous conclusion what exactly the problem is. Please check how you append elements into contactCellHeights
array. It is unsafe to take out of range element from array, so you get a crash.
You can provide full example and we will take a look in details what is the reason of your problem
Found my issue. I set my rowsCount to a constant when it needs to be dynamic.