Search code examples
iosuitableviewstoryboard

Options for Header and Footer in TableView


This is not particularly related to programming, but I am confused and a beginner too so asking here. I am implementing the screen shown below. Clearly, It shows that it can be implemented by using a UITableView with header(Invoice|Date|Vale|Action) and footer(Total).Please ignore the navigation bar. Since, header and footer are just informative with no user interaction, I want to use UILabel as an alternative of header and footer. What I did is attached label in ViewController and between that label added an UITableview. Its working fine on simulator, doesn't have device to test it on.

1)Is this a right way?

2)If it is right, would it show some strange behaviour on device?

3)This approach is okay for autolayout?

This is to be implemented


Solution

  • You are doing it in right way, but if you use UITableViewCell for header labels than you can do it more easily. It just like label of your UITableViewCell and header are of equal width so for indexPath.row == 0 you can set label colors and the label title and for remaining indexes you can do your work as you shown in image.

    For footer using label is good approach.

    EDIT: If the header labels are static then put them in the table header content view so they won't scroll with other cells.