J'ai le code suivant jusqu'ici.Sections dans UITableView avec des cellules personnalisées
var someData = [SomeData]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! Cell1
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as? Cell2
let someData = [indexPath.row]
//Set up labels etc.
return cell!
}
}
J'ai besoin Cell1 qui est une cellule statique et restera toujours à indexPath 0 être dans une section intitulée « Section1 », par exemple & tous être dans une section de l'Cell2 appelé « Section2 »
Autre DataSource & Méthodes Delegate;
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 1
} else {
return someData.count
}
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "Section1" }
else {
return "Section2"
}
}
Cela me renvoie tout ce qu'il faut pour la première section, toutefois, en ce qui concerne la deuxième partie (à cause du code à l'intérieur cellForRowAtIndex quelque part) l'article 2 contient Cell2 à 0. indexPath
Toute aide très appréciée.
Dans l'enregistrement '' de cellForRowAtIndexPath' pour indexPath.section' au lieu de 'indexPath.row' – user1046037
merci, @ user1046037 avait un comportement inhabituel sur l'index 0 de la deuxième section, mais j'ai réalisé que j'avais besoin de me référer à la section ainsi que sur ma taille pour la méthode indexPath. S'il vous plaît ajouter comme une réponse et mal l'accepter. –