Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link Table dataSource and delegate outlets to UITableViewController?

I'm new to Swift/iOS development.

I have a UITableView in my storyboard that I want to populate with some data. In my attempt to do so, I created a class that inherits from UITableViewController. The implementation is not yet complete, but my understanding is that by inheriting from this class I can provide an IBOutlet to both dataSource and delegate.

When I try to drag the outlet into the source file, I don't get the insertion point that I got when I tested this before. See image below: No insertion line! :(

What do I have to do to define this class as the handler for the UITableView?

like image 542
Eric Miller Avatar asked Oct 31 '16 16:10

Eric Miller


People also ask

What is tableView delegate and datasource?

Datasource methods are used to generate tableView cells,header and footer before they are displaying.. Delegate methods provide information about these cells, header and footer along with other user action handlers like cell selection and edit..

What is the difference between delegate and datasource?

A data source is like a delegate except that, instead of being delegated control of the user interface, it is delegated control of data. A data source is an outlet held by NSView and UIView objects such as table views and outline views that require a source from which to populate their rows of visible data.

What is table View delegate?

Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.

What is datasource in Swift IOS?

The data source is generally the list of data that is supplied to the table view. The table views data source methods then iterate on this list and instantiate cells. Table view data sourced methods. There are a lot of different ways to configure your datasource for the table view.


1 Answers

Set your viewController to inherit from UIViewController, not from UITableViewController (It seems like your IB is set up like that). Do not forget to set your class to ZeroconfTableController on the interface builder.

Than, you will be able to set the delegate and datasource. NOTE: the delegate and the datasource will not create IBOutlets.

Assign the delegate and the dataSource the following way: enter image description here

Also make sure, your viewController conforms to the protocols.

class ZeroconfTableController: UIViewController, UITableViewDataSource, UITableViewDelegate { 
like image 109
dirtydanee Avatar answered Oct 24 '22 17:10

dirtydanee