You'll learn how to define a custom UITableView cell in swift for iOS. You'll see the main steps to design and define a custom UITableView cell, a custom uitableview header and an uitableview footer sections.
This is the example for custom UITableView cell you'll obtain using Swift:
Let's create a new swift iOS single view application.
In the main.storyboard uncheck the use size classes feature.
In the main.storyboard let's add the UITableView component. Add the constraints (top, left, right, bottom) to the margin view.
Inside the UITableView let's add an UITableViewCell component. This last component allows us to define a custom cell for the table view.
Create a new cocoa touch iOS file, call it CustomCell and set it as a subclass of UITableViewCell.
Turn back to the main.storyboard, select the cell component previously added and under the identity inspector section set the class to CustomCel, while under the Attribute Inspector set the identifier to cell.
Add now two UILabel components inside the cell, one next to the other. Put the constraints.
Use the Assistant editor to link the labels to the CustomCell class. Once opened the Assistant editor in the bottom view be sure that the CustomCell class is selected. By holding CTRL, drag and drop the two component inside the CustomCell class and assign the variables index and name, respectively.
Link the UITableView component to the viewcontroller.swift too, by calling it tableview.
Let's now start the coding part. Our goal is to fill the table view with 3 different sections, each with a different number of elements.
You'll define a datasource and a delegate for your tableview. In this example the datasource and the delegate will be defined in the viewcontroller class, but they can also be defined in an external swift file as well.
To add a custom UITableView header on the top of each sections, you'll have to turn back to the main.storyboard, select the table view and, under the attribute inspector, set the number of prototype cells to two. The first one will be used for the content while the second one for the custom header section. Create now a new ios cocoa touch file, call it CustomHeader and set it as subclass of UITableViewCell.
Turn back to the main.storyboard, select the bottom cell and set the class to CustomHeader while the identifier to customheader. Add to the second prototype cell the UILabel component.
Open now the assistant editor and link the label to the CustomHeader class. Call it section_title.
In the viewcontroller.swift class add the header section by exploiting the second prototype cell, called customheader.
You can also add on the right the buttons to directly access to the various sections.
Let's now add the footer section by adding this codes inside the viewcontroller.swift.
You can download the example from this link: Download the example.