在 UITableview 中向下滚动时遇到问题。当单元格被重用时,表格向我显示了具有旧内容的单元格。
问题如下:
Swift 想要重用旧单元格,但没有正确清除旧单元格中的旧内容。这会导致单元格具有旧内容,尽管我正在为单元格提供新数据。
UITableView 的架构,如果如下:
问题截图:
问卷开始截图:

向下滚动的表格:

这里的问题是“Handedness”-Cell,它显示了单元格编号 3(因为单元格的重用),这是不对的
numberOfSection-方法
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
Run Code Online (Sandbox Code Playgroud)
numberOfRowsInSection-方法
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(section == 0){
return questionnaireStructure.count
} else {
return 1
}
}
Run Code Online (Sandbox Code Playgroud)
cellForRowAt 方法
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// first section is the normal Questionnaire
if(indexPath.section == 0){
// current questionnaireStructure
let …Run Code Online (Sandbox Code Playgroud)