Using UIViewController

I have used two ways to implement UITableView. The first one that I learned was to use a UIViewController and conform it to use UITableViewDataSource and UITableViewDelegate protocols.

class HomeController: UIViewController, UITableViewDataSource, UITableViewDelegate {

The UITableViewDataSource provides two required methods: numberOfRowsInSection and cellForRowAt. These two methods construct the data model of the tableView.

The UITableViewDelegate defines the appearance of the tableView. For example heightForRowAt method returns the height of the rows.

Using UITableViewController

Another way to create a tableView is to create a UITableViewController class directly. This also means that I don’t have to conform the class to use UITableViewDataSource and UITableViewDelegate protocols. UITableViewController adopts those protocols already.

class HomeController: UITableViewController {

Leave a Comment

Your email address will not be published.