To create a table view with a header in Swift, follow these steps:
UITableView
from the Object Library onto your ViewController
in the storyboard.UITableView
in your ViewController
.UITableView
to your ViewController
.ViewController
:main.swift566 chars15 lines
This code defines the viewForHeaderInSection
method, which is called by the UITableView
to get the view for a particular section's header. In this method, we create a UIView
with a gray background color and a UILabel
with white text that displays the header title. We set the UILabel
as a subview of the UIView
, and then return the UIView
as the header view for the section.
numberOfSections
and numberOfRowsInSection
methods of the UITableViewDataSource
protocol to provide the data for your table view.With these steps, you should now have a table view with a header in your Swift app.
gistlibby LogSnag