Table Header Views in StoryBoards

IosUitableviewXcode4Storyboard

Ios Problem Overview


Is there a way to insert a Table Header View (tableHeaderView) in StoryBoard (like we used to do in Interface Builder)?

Ios Solutions


Solution 1 - Ios

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

Before Drop

After Drop

After Drop

Solution 2 - Ios

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!

Solution 3 - Ios

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTyler DeWittView Question on Stackoverflow
Solution 1 - IosMr RogersView Answer on Stackoverflow
Solution 2 - IosPANKAJ VERMAView Answer on Stackoverflow
Solution 3 - IosfullmoonView Answer on Stackoverflow