2016-05-21 5 views
0

どのようにテーブルビューのデータが重複した問題を解決するには? Object Cのバージョンの回答を検索しましたが、Swiftでは機能していないようです。セル== nilを取得しようとしましたが、エラーになります。スウィフト、テーブルビューのセルを再開できない

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let current_patient = patients[indexPath.row] 
    let cell = myTable.cellForRowAtIndexPath(indexPath) as! PatientTableViewCell 
    if (cell){ 
     let cell = myTable.dequeueReusableCellWithIdentifier("patientCell") as! PatientTableViewCell 
    } 
    let cell = myTable.dequeueReusableCellWithIdentifier("patientCell", forIndexPath: indexPath) as! PatientTableViewCell 
    if(cell != nil){ 
     var subviews = cell.contentView.subviews 
     subviews.removeAll() 
    } 
    //configure cell 
    let type = current_patient.enrollable_type 
    cell.patientTypelbl.text = type 
    return cell 
    } 

2日間の苦労の末、私は最後にそれを理解します。これを解決する鍵は、どのセルが再出力されたかを見つけることです。私が今やっていることは、セルにvar識別子を与えることです。

class PatientTableViewCell: UITableViewCell { 

@IBOutlet weak var followupBtn: UIButton! 
@IBOutlet weak var viewBtn: UIButton! 
@IBOutlet weak var titleType: UILabel! 
@IBOutlet weak var titleID: UILabel! 
@IBOutlet weak var patientTypelbl: UILabel! 
@IBOutlet weak var patientIDlbl: UILabel! 

**var identifier = false** 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let current_patient = patients[indexPath.row] 

    var cell = myTable.dequeueReusableCellWithIdentifier("patientCell") as! PatientTableViewCell 
      if(cell.identifier == true){ 
     cell = myTable.dequeueReusableCellWithIdentifier("patientCell") as! PatientTableViewCell 
    } 
    //config cell 
    cell.identifier = true //important 

私はそれが他の人を助けることを願っています。 :)

答えて

0
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let current_patient = patients[indexPath.row] 
    let cell: PatientTableViewCell! = tableView.dequeueReusableCellWithIdentifier("patientCell") as? PatientTableViewCell 

    //configure cell 
    let type = current_patient.enrollable_type 
    cell.patientTypelbl.text = type 
    return cell 
} 
+0

申し訳ありませんが、データはまだ重なっています。 –

関連する問題