0

Right now I'm trying to wrap my head around Objective C and XCode. I'm playing around with UITableView and I have problems separating the concepts behind

  • UITableViewController
  • UITableViewDelegate
  • UITableViewDataSource

I'm familiar with the MVC pattern, I learned from the Apple Developer Docs that their frameworks use delegates to "specialize" classes without subclassing and the data source class defines how to map the data from the model onto the view (please correct me if I'm wrong).

When I created a TableViewController by selecting New File.. > Cocoa Touch Class > UIViewController subclass (checking UITableViewController subclass) I was puzzled to see that the template included all the functions from UITableViewDelegate and UITableViewDataSource without specifying in the header file that the TableViewController implements these protocols. The documentation for UITableViewController says it "conforms to UITableViewDelegate and UITableViewDataSource". Does that mean it implements those protocols ?

So my question is: Is UITableViewController a mere convenience class combining UITableViewDelegate and UITableViewDataSource or am I missing something? And do I need a UITableViewController if I provide separate UITableViewDelegate and UITableViewDataSource?

Thank you!

das_weezul
  • 6,082
  • 2
  • 28
  • 33

1 Answers1

1

UITableViewController is a controller pre-configured with with a UITableView and with itself set as the table view's delegate and data source.

So yes, it's pretty much a convenience class.

You don't need to use it, particularly if you provide your own data source and delegate.

Terry Wilcox
  • 9,010
  • 1
  • 34
  • 36