ios swift 3 重新加载tableView时删除每个单元格的内容

ios swift 3 delete contents of each cell when reloading tableView

我正在使用 DLRadioButton 创建一个 quizApp,在 tableView 的每个单元格中都有一个标签,标签是从 storyBoard(带有标签)设置的,但我已经设置了 radioButtons当我单击下一个按钮传递到下一个问题时,以编程方式进行更好的设计新的 Radiobutton 与旧的 Radiobutton 重叠

这是第一个问题

这是第二张图

下面是我的代码

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell : UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")!
    var reponse = rep[(indexPath as NSIndexPath).row]


     let content:UILabel=cell.viewWithTag(111) as! UILabel
    //var ra:UIButton=cell.viewWithTag(112) as! UIButton

    content.text=reponse["rep"] as? String
    content.sizeToFit()
    let repiii = reponse["rep"] as? String

   // var radio = DLRadioButton()
    if (self.type=="case à cocher"){
       // cell.contentView.delete(radioButtons)
        let frame = CGRect(x: 50, y: 20, width: 200, height: 40)
       let squareButton = self.createRadioButton(frame: frame, title:repiii!, color:  UIColor.red,compt: squareButtons.count,sqaure:1);

        squareButtons.append(squareButton)
         cell.contentView.addSubview(squareButton)
    }
    else{
        let frame = CGRect(x: 50, y: 20, width: 200, height: 40)

       let radioButton = self.createRadioButton(frame: frame, title:repiii!, color:  UIColor.blue,compt: radioButtons.count,sqaure:0);

       //radioButton.isMultipleSelectionEnabled = true
        print(radioButtons.count)
        radioButtons.append(radioButton)
     cell.contentView.addSubview(radioButton)
    }

    return cell
}

欢迎任何建议

在您的代码中,就在

行之后
let cell : UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")!

添加这个:

for subview in cell.contentView.subviews {
    subview.removeFromSuperView()
}