2017-03-09 117 views
0

我想从静态UITableViewController中的单元格创建一个头。 tableView控制器包含5个静态单元。
在第一个单元格中,我放下了4个标签,创建了一个类CustomHeader。 在viewForHeaderInSection中,我得到错误Value of type 'UITableViewCell' has no member。我知道,如果我使用原型单元格,我将能够使用tableView.dequeueReusableCell,但我不知道如何在静态表格中执行此操作。'UITableViewCell'类型的值没有成员 - 静态表Swift 3

import UIKit 

class CustomHeader: UITableViewCell { 

    @IBOutlet weak var dateHeaderlabel: UILabel! 
    @IBOutlet weak var hourHeaderlabel: UILabel! 
    @IBOutlet weak var totalHoursHeaderlabel: UILabel! 
    @IBOutlet weak var priceHeaderlabel: UILabel! 

override func setSelected(_ selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 
    } 
} 


class ManagedTable: UITableViewController,UITextFieldDelegate{ 

    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 


    let index = tableView.indexPathsForVisibleRows?.first 
    let headerCell = tableView.cellForRow(at: index!) 

// I get error on the next 4 lines Value of type 'UITableViewCell' has no  
    // member dataHeaderlabel...etc 

    headerCell.dateHeaderlabel.text = StructS.headerDate 
    headerCell.hourHeaderlabel.text = StructS.headerHours + " " + "-" 
    headerCell.totalHoursHeaderlabel.text = String("\(Double(StructS.numberHours) + StructS.extrasHours) HOURS") 
    headerCell.priceHeaderlabel.text = String("£\(StructS.price + StructS.totalExtras + FullData.finalSuppliesAmount)") 

    headerCell.backgroundColor = UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1.0) 
    return headerCell 
    } 
} 
+0

你尝试投headerCell到CustomHeader像'让headerCell = tableView.cellForRow(在:指数!)为! CustomHeader' – AtaerCaner

+0

@AtaerCaner我试过了,它不起作用。如果可以的话,你可以在Xcode中使用它。 – bibscy

+0

尝试'如果让headerCell = tableView.cellForRow(at:index!)as? CustomHeader',然后将所有其余代码放在该块中的'headerCell'成员变量中。 –

回答

1

尝试if let headerCell = tableView.cellForRow(at: index!) as? CustomHeader然后将所有剩余的代码放在该块中的headerCell成员变量中。它看起来像你没有铸造headerCell作为你的自定义类。

还要确保index被设置为你希望

相关问题