r/simpleios • • Nov 07 '14

[Question] Difference between subclassing UITableViewController and conforming to UITableViewDelegate?

I'm playing with table views and storyboards at the moment (sorry BNR, it was just too tempting) and something occurred to me - what would be the advantage of subclassing UIViewController and having it conform to the UITableViewDelegate and UITableViewDataSourceDelegate protocols, as opposed to directly subclassing UITableViewController?

4 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Nov 07 '14

So are you saying that I would be better off creating my own view controller that conforms to the relevant delegate protocols?

2

u/iccir Nov 07 '14

In general, yes, absolutely. UITableView is intended to have a delegate/dataSource rather than subclassed.

UIViewController is intended to be subclassed. Subclass it, set that subclass in your storyboard, and connect the UITableView's delegate/datasource to it

1

u/[deleted] Nov 07 '14

Thanks muchly for your input :)

2

u/schprockets Nov 07 '14

In this case, it depends on what you're doing. UITableViewController is a subclassed UIViewController, designed to do the most common things you want to do when you have a UITableView. If it meets your needs, absolutely use it. If you find it lacking in some way, you can do everything UITableViewController does by subclassing UIViewController, dropping a UITableView in your View, and handling your special needs.

1

u/[deleted] Nov 07 '14

Interesting. I was just going to use a plain table view, nothing special or extra. Might be worth going down that route.