why am I not able to connect the element such as label and button to the UIView class I have created.I have named it in the storyboard as well.
Asked
Active
Viewed 80 times
-1
-
Please show us what have you tried so far. – Rob Mar 06 '20 at 07:32
-
@Rob I linked the view to my TableViewController file as an IBOutlet – ritika gupta Mar 06 '20 at 07:37
-
You could simply check the this link to get an idea https://stackoverflow.com/a/33007472/5089923 – shinoy Mar 06 '20 at 07:46
-
Does this answer your question? [Access each header and controls in the tableview in swift](https://stackoverflow.com/questions/33007142/access-each-header-and-controls-in-the-tableview-in-swift) – Shubhendu Devmurari Mar 06 '20 at 07:48
-
@ShubhDev I have section headers as well so this is confusing me.Apart from that I too tried creating a UIView class for the view but couldn't connect those switch and label in to it. – ritika gupta Mar 06 '20 at 13:06
1 Answers
1
Subclass UITableViewHeaderFooterView
, then connect outlets from IB/Storyboard.
Then you can access these through viewForHeaderInSection
method:
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "CustomHeader") as! CustomHeader
headerView.Label.text = "View all calls"
return headerView
}

Tom
- 513
- 2
- 5
- 20