2017-07-12 3 views
0
class CalenderCell: UITableViewCell { 

    @IBOutlet var lblDay: UILabel! 
    @IBOutlet var lblRest: UILabel! 
    @IBOutlet var imgCompleted: UIImageView! 

    override func awakeFromNib() 
    { 
     super.awakeFromNib() 
    } 

    func updateCell(exerciseobject : Exercise) 
    { 
     let resttext = NSLocalizedString("restday", comment: "") 
     let day = NSLocalizedString("day", comment: "") 
     let dayexercise = "\(day) \(exerciseobject.exerciseDayID)" 

     if !exerciseobject.exerciseRestDay 
     { 
      lblDay.text = dayexercise 
      if exerciseobject.exerciseDayStatus 
      { 
       imgCompleted.isHidden = false 
      } 
      else 
      { 
       imgCompleted.isHidden = true 
      } 
      lblRest.isHidden = true 

     } 
     else 
     { 
      lblDay.isHidden = true 
      imgCompleted.isHidden = true 
      lblRest.text = resttext 
      viewWithTag(100)?.backgroundColor = UIColor(red:1.00, green:0.21, blue:0.28, alpha:1.0) 
     } 
    } 
} 

上記は私のカスタムセルクラスであり、以下は私のtableviewクラスです。
アプリを構築しようとすると、すべてが完璧に機能しますが、速くスクロールするたびに、データが不一致であるか、または同じデータがより多くのセルに割り当てられます。UITableView速いスクロールで一致しないカスタムセルデータ

私が試した:私のカスタムセルクラスの

prepareforreuse() 
{ 
    //clearing label and images here 
} 

をまだ速いscrollviewデータの不一致を取得

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
{ 
    if let cell = calenderTable.dequeueReusableCell(withIdentifier: "CalenderCell", for: indexPath) as? CalenderCell 
    { 

     cell.updateCell(exerciseobject: days[indexPath.row]) 
     return cell 
    } 

    else 
    { 
     return UITableViewCell() 
    } 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
    return days.count 
} 

答えて

0

いずれかの値をデフォルトまたはすべて更新することを確認するためにprepareForReuseを使用して、コントロールをリセットupdateCellメソッド内のすべてのパスの状態。

func updateCell(exerciseobject : Exercise) 
{ 
    let resttext = NSLocalizedString("restday", comment: "") 
    let day = NSLocalizedString("day", comment: "") 
    let dayexercise = "\(day) \(exerciseobject.exerciseDayID)" 

    if !exerciseobject.exerciseRestDay 
    { 
     lblDay.text = dayexercise 
     lblDay.isHidden = false 
     if exerciseobject.exerciseDayStatus 
     { 
      imgCompleted.isHidden = false 
     } 
     else 
     { 
      imgCompleted.isHidden = true 
     } 
     lblRest.isHidden = true 

     viewWithTag(100)?.backgroundColor = nil 
    } 
    else 
    { 
     lblDay.isHidden = true 
     imgCompleted.isHidden = true 
     lblRest.text = resttext 
     lblRest.isHidden = false 
     viewWithTag(100)?.backgroundColor = UIColor(red:1.00, green:0.21, blue:0.28, alpha:1.0) 
    } 
} 
+0

ありがとうございました。 – Rajesh2701

関連する問題