【发布时间】:2016-08-07 14:18:50
【问题描述】:
我有以下表格视图单元格:
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 我怎么能解决这个问题?
-
因此,如果您在第 2 行切换开关,它是否会影响其他任何事情,还是只会在第 1 行发生??
-
我有一个类似的问题,通过跟踪数组中的相关单元格来解决。看看这里的答案:stackoverflow.com/questions/34369939/…
-
@satheeshwaran 只是第 1 行总是影响最后一行
标签: ios swift uitableview uiswitch valuechangelistener