J'ai créé une cellule personnalisée dans mon projet Swift 4 qui inclut un commutateur. Lorsque je sélectionne un commutateur, je sélectionne tous les 10 commutateurs dans le tableau. Il y a 34 cellules dans la table. J'ai essayé plusieurs combinaisons différentes d'interaction utilisateur activée/désactivée. Même si l'état des commutateurs non sélectionnés est activé, les actions associées ne se déclenchent pas. Voici le code qui déclenche l'action:UISwitch dans une table sélectionne plusieurs cellules lorsque l'état de commutation est activé
@IBAction func SwitchAction(_ sender: UISwitch) {
let switchPosition = sender.convert(CGPoint(), to:tableView)
let indexPath = tableView.indexPathForRow(at:switchPosition)
let ipath = indexPath?.row
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return taskList.count
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 75
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
let cell: customTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! customTableViewCell
cell.LabelSelect.text=taskList[indexPath.row]
return cell
}
Bienvenue dans Stack Overflow - c'est bien de vous avoir. S'il vous plaît lire Comment puis-je poser une bonne question? https://stackoverflow.com/help/how-to-ask et Comment créer un exemple minimal, complet et vérifiable pour aider à maintenir le contenu de Stack Overflows au niveau le plus élevé possible et augmenter vos chances d'obtenir une réponse appropriée. https://stackoverflow.com/help/mcve –
L'action de votre commutateur vous donne-t-elle l'index correct? – Tj3n
ajouter une cible pour basculer dans la méthode cellforrowatindexpath – Vinodh