У меня есть следующий класс для представления таблицы ячейки:изменить переключатель на Tableview строке затрагивая другие строки
class QuestionCell: UITableViewCell {
@IBOutlet weak var questionAnswer: UISwitch!
@IBOutlet weak var questionLabel: UILabel!
var data: Answer?
func configureForQuestion(data: Answer) {
print("configureForQuestion triggered")
questionLabel.text = data.question
self.data = data
}
@IBAction func questionAnswerChanged(sender: UISwitch) {
data?.answer = sender.on
}
}
Эта клетка состоит из метки и переключателя. В настоящее время, когда я изменяю статус переключателя для первой строки, он также изменяется для последней строки. Никакие другие строки, похоже, не связаны таким образом. Я довольно тупой на этом.
Дополнительно:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return answers.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(TableView.CellIdentifiers.QuestionCell, forIndexPath: indexPath) as! QuestionCell
cell.configureForQuestion(answers[indexPath.row])
return cell
}
Это подсказка, tableView.dequeueReusableCellWithIdentifier(), создающие проблему с помощью dequedCells. – satheeshwaran
@satheeshwaran, так что я могу обойти это? – user2363025
Итак, если вы переключаете переключатель в строке 2, это влияет на что-то еще или это просто происходит со строкой 1 всегда? – satheeshwaran