First of all, that is completely independent of which language
you use, Swift or Objective-C.
But there are two different cases which may cause the confusion:
A UITableViewController
subclass:
UITableViewController
already conforms to UITableViewDataSource
and UITableViewDelegate
. It has a tableView
property,
whose dataSource
and delegate
property are already set to self
.
In your subclass, you typically override the
data source and delegate methods.
A UIViewController
subclass with a UITableView
property:
Here you have defined a UITableView
property in your subclass
and initialize it in your code, or
connect it to a table view in the interface builder.
In this case you have to set the dataSource
and delegate
property of the tableview, either in code or in the interface
builder, as explained in luk2302's answer.
If data source and delegate are the view controller itself,
then you have to declare the protocol conformance explicitly,
and implement the
data source and delegate methods (but without overriding
a superclass method).
Of course, in both cases, the table view data source and the delegate
can be set to a different object, it does not have to be
the view controller itself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…