I am using a custom cell in my tableView but when I run i get the error which I have mentioned in my question.
override func viewDidLoad() {
super.viewDidLoad()
alertTable.register(UINib(nibName: "Alert1TableViewCell", bundle: nil), forCellReuseIdentifier: "Alert1TableViewCell")
}
extension AlertViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.alerts?.count ?? 0;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// let cell = alertTable.dequeueReusableCell(withIdentifier: "Alert1TableViewCell")!
// let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! Alert1TableViewCell;
let cell = tableView.dequeueReusableCell(withIdentifier: "Alert1TableViewCell", for: indexPath) as! Alert1TableViewCell
cell.alert = self.alerts?[indexPath.row];
return cell;
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false);
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension;
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 100;
}
}
class Alert1TableViewCell: UITableViewCell {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var icon: UIImageView!
public var alert : Alert?{
didSet{
self.nameLabel.text = self.alert?.deviceName;
if self.alert?.alertType?.lowercased() == "ignition on"{
self.icon.image = UIImage(named: "alert_ignition_on");
}else if self.alert?.alertType?.lowercased() == "ignition off"{
self.icon.image = UIImage(named: "alert_ignition_off");
}else if self.alert?.alertType?.lowercased() == "overspeed"{
self.icon.image = UIImage(named: "alert_overspeed");
}else{
self.icon.image = UIImage(named: "alert_default");
}
let twelevehrsformat = DateUtil.format(self.alert?.dtServer ?? "", fromFormat: "yyyy-MM-dd HH:mm:ss", toFormat: "dd-MMM-yyyy hh:mm:ss a", tf: false);
let twentyfourhrsformat = DateUtil.format(self.alert?.dtServer ?? "" , fromFormat: "yyyy-MM-dd HH:mm:ss", toFormat: "dd-MMM-yy HH:mm:ss a", tf: true)
if UserDefaults.standard.bool(forKey: "hrsFormat") == true {
self.timeLabel.text = twentyfourhrsformat
} else {
self.timeLabel.text = twelevehrsformat
}
self.descriptionLabel.text = self.alert?.address;
print(self.alert?.address ?? "")
}
}
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
}
}