A custom header class is created for the header, view using xib. Trying to get the value of UITextField from that header class. Below is the code:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let customHeaderView = Bundle.main.loadNibNamed("AddHeaderTableViewCell", owner: self, options: nil)?.last as! AddHeaderTableViewCell
customHeaderView.txtFieldAdd.placeholder = ""
return customHeaderView
}
When trying to get value from the textfields below:
@objc func addMoreToMytask(sender: UIButton!) {
isAddStep = false
let header = tblAddedTasks.headerView(forSection: 0) as? AddHeaderTableViewCell
let sectionTitle = header?.textLabel?.text
arrAdded.append((header?.txtFieldAdd.text!)!)
tblAddedTasks.reloadData()
}
It is giving error in this line
let header = tblAddedTasks.headerView(forSection: 0) as? AddHeaderTableViewCell
Gives warning and crash when run
Cast from 'UITableViewHeaderFooterView?' to unrelated type 'AddHeaderTableViewCell' always fails
Please guide for the same.