Reputation: 2718
I want to create a header from a cell in a static UITableViewController.
The tableView controller contains 5 static cells.
In the first cell I dropped 4 lables, created a class CustomHeader
.
In viewForHeaderInSection I get the error Value of type 'UITableViewCell' has no member
. I know that if I used prototype cells, I would have been able to use tableView.dequeueReusableCell
, but I don't know how to do it in static table.
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
}
}
Upvotes: 0
Views: 1144
Reputation: 527
Try if let headerCell = tableView.cellForRow(at: index!) as? CustomHeader
and then put all the rest of the code for headerCell member variables inside that block. It looks like you weren't casting headerCell
as your custom class.
Also make sure that index
is being set as you expected
Upvotes: 1