表视图中重复/重复的单元格

时间:2019-07-07 04:55:36

标签: xcode uitableview cell

我有一个tableView,由于某种原因,单元格自我重复。我已经尝试解决了一段时间,但是我却无法做到。

我的代码为

     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


     if indexPath.section == 1 {
     let mileRangeCell = MileRangeCell(style: .default, reuseIdentifier: nil)
         mileRangeCell.mileSlider.addTarget(self, action: #selector(handleMileChange), for: .valueChanged)
        let mile = user?.mileRange ?? SettingsViewController.defaultMile
        mileRangeCell.mileLabel.text = "Miles \(mile)"
        mileRangeCell.mileSlider.value = Float(mile)
        return mileRangeCell
    }


    if indexPath.section == 2 {
        let costRangeCell = AgeRangeCell(style: .default, reuseIdentifier: nil)
        costRangeCell.minSlider.addTarget(self, action: #selector(handleMinAgeChange), for: .valueChanged)
        costRangeCell.maxSlider.addTarget(self, action: #selector(handleMaxAgeChange), for: .valueChanged)
        let minAge = user?.minSeekingCost ?? SettingsViewController.defaultMinSeekingCost
        let maxAge = user?.maxSeekingCost ?? SettingsViewController.defaultMaxSeekingCost

        costRangeCell.minLabel.text = "Min $\(minAge)"
        costRangeCell.maxLabel.text = "Max $\(maxAge)"
        costRangeCell.minSlider.value = Float(minAge)
        costRangeCell.maxSlider.value = Float(maxAge)
        return costRangeCell
    }
    let cell = SettingsCell(style: .default, reuseIdentifier: nil)

    let uid = Auth.auth().currentUser?.uid

    Database.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in

        guard let dictionary = snapshot.value as? [String : Any] else { return }

        let user = User(dictionary: dictionary as [String : AnyObject])

switch indexPath.section {

        case 3:

        cell.pntextField.placeholder = "Enter Phone"
        cell.pntextField.text = user.number
        cell.pntextField.addTarget(self, action: #selector(self.handlePhoneChange), for: .editingChanged)

        cell.textField.placeholder = "Enter Email"
        cell.textField.text = user.email
        cell.textField.addTarget(self, action: #selector(self.handleEmailChange), for: .editingChanged)

        cell.textField2.placeholder = "Enter Address"
        cell.textField2.text = user.address
        cell.textField2.addTarget(self, action: #selector(self.handleAddressChange), for: .editingChanged)

      case 4:

        cell.textField3.placeholder = "Enter Skills"
        cell.textField3.text = user.skills
        cell.textField3.addTarget(self, action: #selector(self.handleSkillsChange), for: .editingChanged)

        cell.textField4.placeholder = "Enter Education"
        cell.textField4.text = user.education
        cell.textField4.addTarget(self, action: #selector(self.handleEducationChange), for: .editingChanged)

        cell.textField5.placeholder = "Enter Bio"
        cell.textField5.text = user.bio
        cell.textField5.addTarget(self, action: #selector(self.handleBioChange), for: .editingChanged)

        }

}, withCancel: { (err) in
print("attempting to load information")

})
    return cell
}

在我的视图控制器中,我看到image repeating

repeating

我只希望textViews在前两个单元格中。在其余的部分中不再重复。如果有人可以将我引导到正确的地方,我将不胜感激。

0 个答案:

没有答案