title: Swift 3 - Problems in reusing cell with multiple custom cells
body: <p>I've got problems when I scroll down in my UITableview. The table shows me cells with old content when the cell is reused. </p>
  
  <p>The Probleme is the following:</p>
  
  <p>Swift wants to reuse an old cell, but doesn't properly clear the old content from the old cell. This leads to cells with old content, although I'm providing new data to the cells.</p>
  
  <p>Architecture of the UITableView if the following:</p>
  
  <ul>
  <li>Each custom cell has their own identifier</li>
  <li>Each custom cell is separated in an own class</li>
  </ul>
  
  <p>Screenshots of the problem:</p>
  
  <p><strong>Beginning of the Questionnaire Screen Shot</strong>:</p>
  
  <p><img src="https://i.stack.imgur.com/MLFAZ.png" alt="Screen Shot"></p>
  
  <p><strong>The scrolled down table</strong>:</p>
  
  <p><img src="https://i.stack.imgur.com/NhUI1.png" alt="Screen Shot"></p>
  
  <p>The problem here is the "Handedness"-Cell which is showing the cell number 3 (because of the reuse of the cell), which is not right</p>
  
  <p><strong>The numberOfSection-Method</strong></p>
  
  <pre><code>override func numberOfSections(in tableView: UITableView) -&gt; Int {
      return 2
  }
  </code></pre>
  
  <p><strong>The numberOfRowsInSection-Method</strong></p>
  
  <pre><code>override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      if(section == 0){
          return questionnaireStructure.count
      } else {
          return 1
      }
  }
  </code></pre>
  
  <p><strong>The cellForRowAt-Method</strong></p>
  
  <pre><code>override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      // first section is the normal Questionnaire
      if(indexPath.section == 0){
  
          // current questionnaireStructure
          let questStruct:QuestionnaireStructure? = questionnaireStructure[indexPath.row]
  
          // current cell is a "Headline"
          if(questStruct?.elementtype == "elements/headlines"){
              let cell = tableView.dequeueReusableCell(withIdentifier: "HeadlineStructureCellID", for: indexPath) as! Headline
              cell.headline.text = questStruct?.headline
              cell.selectionStyle = UITableViewCellSelectionStyle.none
              return cell
          } else if(questStruct?.elementtype == "elements/texts"){
              // current cell is a "texts"
              let cell = tableView.dequeueReusableCell(withIdentifier: "TextsStructureCellID", for: indexPath) as! Texts
              cell.textsLabel.text = questStruct?.text
              cell.selectionStyle = UITableViewCellSelectionStyle.none
              return cell
          } else if(questStruct?.questiontype == "Slider"){
              // currrent cell is a "slider-Question"
              let cell = tableView.dequeueReusableCell(withIdentifier: "QuestionSliderStructureCellID", for: indexPath) as! Slider
              cell.sliderQuestion.text = questStruct?.question
              cell.selectionStyle = UITableViewCellSelectionStyle.none
  
              let values = (questStruct?.values)!
              let valueArray = values.array as! [Values]
              cell.slider.minimumValue = Float(valueArray[0].min)
              cell.slider.maximumValue = Float(valueArray[0].max)
              let answers = (questStruct?.answers)!
              let answerArray = answers.array as! [Answers]
              cell.minLabel.text = answerArray[0].label
              cell.maxLabel.text = answerArray[1].label
  
              return cell
          } else if(questStruct?.questiontype == "SingleChoice"){
              let cell = tableView.dequeueReusableCell(withIdentifier: "QuestionSingleChoiceStructureCellID", for: indexPath) as! SingleChoiceCell
              let radioButtonController = SSRadioButtonsController()
              radioButtonController.delegate = self
              radioButtonController.shouldLetDeSelect = true
              cell.radioButtonController = radioButtonController
              cell.updateCellData(questStruct: questStruct!, indexInTable: indexPath.row)
  
              return cell
          } else if(questStruct?.questiontype == "MultipleChoice"){
              let cell = tableView.dequeueReusableCell(withIdentifier: "QuestionMultipleChoiceStructureCellID", for: indexPath) as! MultipleChoiceCell
              cell.multQuestionLabel.text = questStruct?.question
              cell.questStruct = questStruct
  
              return cell
          } else if(questStruct?.questiontype == "YesNoSwitch"){
              let cell = tableView.dequeueReusableCell(withIdentifier: "QuestionYesNoSwitchStructureCellID", for: indexPath) as! YesNoSwitch
              cell.yesNoQuestion.text = questStruct?.question
              cell.selectionStyle = UITableViewCellSelectionStyle.none
  
              return cell
          } else if(questStruct?.questiontype == "TextDate"){
              let cell = tableView.dequeueReusableCell(withIdentifier: "Datepicker", for: indexPath) as! DatePicker
              cell.question.text = questStruct?.question
              cell.selectionStyle = UITableViewCellSelectionStyle.none
  
              return cell
          } else {
              let cell = tableView.dequeueReusableCell(withIdentifier: "QuestionSingleChoiceStructureCellID", for: indexPath) as! SingleChoiceCell
              //cell.singleChoiceLabel.text = questStruct?.question
              cell.selectionStyle = UITableViewCellSelectionStyle.none
              return cell
          }
  
      } else {
          //last section is the save button
          // show the save button when the Questionnaire is loaded
          if(questionnaireStructure.count != 0){
              let cell = tableView.dequeueReusableCell(withIdentifier: "SaveStructureCellID", for: indexPath) as! SaveQuestionnaire
              cell.selectionStyle = UITableViewCellSelectionStyle.none
              return cell
          } else {
              let cell = tableView.dequeueReusableCell(withIdentifier: "TextsStructureCellID", for: indexPath) as! Texts
              cell.selectionStyle = UITableViewCellSelectionStyle.none
              return cell
          }
      }
  
  }
  </code></pre>
  
  <p>What I checked:</p>
  
  <ul>
  <li>the data of "questStruct" is providing the latest data</li>
  <li>overriding the "prepareForReuse"-Methode without success</li>
  </ul>