Устранить return UITableViewCell
.
Некоторые люди могут сказать return UITableViewCell()
, но я бы предпочел рассматривать этот случай как ошибку, которая действительно есть, например,
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.row {
case 0:
return tableView.dequeueReusableCell(withIdentifier: "TripDriverDetailsCell", for: indexPath)
case 1:
return tableView.dequeueReusableCell(withIdentifier: "TripFareDetailsCell", for: indexPath)
case 2:
return tableView.dequeueReusableCell(withIdentifier: "TripPaymentModeCell", for: indexPath)
default:
fatalError("Unexpected row number \(indexPath.row)")
}
}
heightForRowAt
должен аналогичным образом обрабатывать сценарий, где indexPath.row
не равен 0, 1 или 2, например ::
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.row {
case 0: return 230
case 1: return 200
case 2: return 120
default: fatalError("Unexpected row number \(indexPath.row)")
}
}