ios swift 3 удаляет содержимое каждой ячейки при перезагрузке tableView - PullRequest
0 голосов
/ 22 мая 2018

Я создаю приложение quizApp, используя DLRadioButton с меткой в ​​каждой ячейке tableView, метка установлена ​​на storyBoard (с меткой), но я установил radioButtons программно для улучшения дизайна, когда я нажимаю кнопку Далее.нажмите кнопку, чтобы перейти к следующему вопросу. Новая радиопереключатель перекрывается со старой радиопереключателем

. Вот первый вопрос

enter image description here

вот второе изображение

enter image description here

Ниже мой код

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
}

приветствуется любое предложение

1 Ответ

0 голосов
/ 22 мая 2018

в вашем коде, сразу после строки

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

добавить это:

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