UITableView中的自定义单元格标签不会填充

时间:2016-01-12 16:25:43

标签: ios iphone uitableview

在我的故事板上是一个带有两个视图控制器的标签栏控制器。第一个视图控制器有一个UITableView,第二个视图控制器用于收集将在第一个视图控制器上以表格视图格式显示的数据。

为此,我创建了四个swift文件:

  1. TARISKTREATMENT.swift - 包含链接到第一个视图控制器的类TARISKTREATMENT(具有UITableView的视图)

  2. TAADDRISKTREATMENT.swift - 包含链接到第二个视图控制器的TAADDRISKTREATMENT类。

  3. TREATMENTS.swift - 用于收集在第二个视图控制器上输入的数据的结构。

  4. CUSTOMTREATMENTCELL.swift - 自定义单元格的UITableViewCell类。

  5. 第二个视图控制器完美地收集用户的数据,当我运行打印命令时,我可以看到数据实际上在结构中。

    由于某些原因,来自TARISKTREATMENT.swift的代码不会填充自定义单元格。

    我在这里做错了什么?

    CODE:TARISKTREATMENT.swift(使用UITableView查看控制器1 - 那个不能正常工作的人......)

    import UIKit
    
    class TARISKTREATMENT: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
        @IBOutlet weak var TreatmentsTableView: UITableView!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            TreatmentsTableView.dataSource = self
            TreatmentsTableView.delegate = self
            TreatmentsTableView.reloadData()
    
        }//END - viewDidLoad
    
        func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return TreatmentsManager.newTreatments.count
        }
    
        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
            let IndividualCell = TreatmentsTableView.dequeueReusableCellWithIdentifier("TreatmentCell", forIndexPath: indexPath) as! CUSTOMTREATMENTCELL
    
            IndividualCell.outletLabel_TreatmentPackageName.text = TreatmentsManager.newTreatments[indexPath.row].varTreatmentPackageName
    
            IndividualCell.outletLabel_TreatmentDescription.text = TreatmentsManager.newTreatments[indexPath.row].varTreatmentPackageDetail
    
            IndividualCell.outletLabel_TreatmentResponsiblePerson.text = TreatmentsManager.newTreatments[indexPath.row].varTreatmentResponsiblePerson
    
            IndividualCell.outletLabel_TreatmentDTGCompleted.text = String(TreatmentsManager.newTreatments[indexPath.row].varTreatmentDTGCompleted)
    
            let varSelectPriorityPic = TreatmentsManager.newTreatments[indexPath.row].varTreatmentPriority
    
            switch varSelectPriorityPic {   
            case "HIGH":
                IndividualCell.outletImage_TreatmentPriority.image = imageTreatmentPriorityHigh
            case "MEDIUM":
                IndividualCell.outletImage_TreatmentPriority.image = imageTreatmentPriorityMedium
            case "LOW":
                IndividualCell.outletImage_TreatmentPriority.image = imageTreatmentPriorityLow
            default:
                break
            }
            return IndividualCell
        }
    
        func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){
            if (editingStyle == UITableViewCellEditingStyle.Delete){
    
                TreatmentsManager.newTreatments.removeAtIndex(indexPath.row)
                TreatmentsTableView.reloadData()
            }
        }
    }
    

    CODE:TREATMENTS.swift

    import UIKit
    
    var TreatmentsManager: classTreatmentsManager = classTreatmentsManager()
    
    struct structTreatment {
        var varTreatmentPackageName : String
        var varTreatmentPackageDetail : String
        var varTreatmentResponsiblePerson : String
        var varTreatmentPriority : String
        var varTreatmentDTGCompleted : NSDate
    }
    
    class classTreatmentsManager: NSObject {
    
        var newTreatments = [structTreatment]()
    
        func funcAddTreatment(varTreatmentPackageName: String, varTreatmentPackageDetail: String, varTreatmentResponsiblePerson: String, varTreatmentPriority: String, varTreatmentDTGCompleted: NSDate){
    
            newTreatments.append(structTreatment(varTreatmentPackageName: varTreatmentPackageName, varTreatmentPackageDetail: varTreatmentPackageDetail, varTreatmentResponsiblePerson: varTreatmentResponsiblePerson, varTreatmentPriority: varTreatmentPriority, varTreatmentDTGCompleted: varTreatmentDTGCompleted))
        }
    }
    

    代码:CUSTOMTREATMENTCELL.swift

    import UIKit
    
    class CUSTOMTREATMENTCELL: UITableViewCell {
    
        @IBOutlet weak var outletImage_TreatmentPriority: UIImageView!
    
        @IBOutlet weak var outletLabel_TreatmentPackageName: UILabel!
    
        @IBOutlet weak var outletLabel_TreatmentDescription: UILabel!
    
        @IBOutlet weak var outletLabel_TreatmentResponsiblePerson: UILabel!
    
        @IBOutlet weak var outletLabel_TreatmentDTGCompleted: UILabel!
    
        override func awakeFromNib() {
            super.awakeFromNib()
            // Initialization code
        }
    
        override func setSelected(selected: Bool, animated: Bool) {
            super.setSelected(selected, animated: animated)
    
            // Configure the view for the selected state
        }
    }
    

    我上传了一个小视频来展示(不)发生的事件here

    感谢您的协助 - 谢谢!

1 个答案:

答案 0 :(得分:1)

代码中的一切都很好。您错过的是重新加载数据:

mergeDeep(this, { a: { b: { c: 123 } } });
// or
const merged = mergeDeep({a: 1}, { b : { c: { d: { e: 12345}}}});  
console.dir(merged); // { a: 1, b: { c: { d: [Object] } } }