Chaque fois que j'exécute l'application, le tableView
n'a aucune donnée, attendant que l'utilisateur entre. Le problème est que si le numberOfSections
est 1, cela fonctionne très bien, mais quand je change à 2, il se bloque parce que l'indice hors de portéeUITableView Section Index Hors des limites mais ce n'est pas vraiment hors limites
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "expenseCell") as? ExpenseCell else { return UITableViewCell() }
let budget = userBudget[indexPath.section][indexPath.row]
cell.delegate = self
cell.configureCell(budget: budget)
return cell
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.none
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userBudget[section].count // <- Crash here
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Practice with Sections \(section)"
}
Que sont les données dans userBudget arrray? – iPatel
Il n'y a qu'un seul tableau dans 'userBudget'. Donc d'abord la valeur de 'userBudget' et assurez-vous qu'il a plusieurs tableaux. –
changez votre numberOfSections pour retourner userBudget? .count ?? 0 (si userBudget est optionnel) ow userBudget.count. Ne pas coder en dur la valeur. –