Reputation: 23576
Is there a way to insert a Table Header View (tableHeaderView) in StoryBoard (like we used to do in Interface Builder)?
Upvotes: 193
Views: 97839
Reputation: 8671
Dragging and dropping a view on top of the tableview worked for only one screen size, at least in Xcode 11. It didn't size well on different screens.
I just created a view and left it there behind the tableview in storyboard. I created an IBOutlet for it:
@IBOutlet weak var audioView: UIView!
Then in tableview code I did:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return audioView
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 142
}
It worked well on all screen sizes.
Upvotes: -3
Reputation: 3580
You can do this easily by dragging your UIView
/UIImageView
just below the UITableView
in the document outline (instead of the layout).
If you try to drag in the layout instead of document outline the UITableViewCell
will jump to the top handling which is frustrating!
Upvotes: 11
Reputation: 6251
It looks like one simply drags a control to the top of the table view. I didn't expect it to be that easy.
Before Drop
After Drop
Upvotes: 352