golddove
golddove

Reputation: 1206

What to use as delegate and data source for a table view subview?

I have a UITableView as a subview in a UIViewController. I am not sure if I can just create a UITableViewController as it is not a whole new "window"; it is simply a subview.

Correct if I am wrong, but the best thing to do is to create a class and set it as the delegate and data source for the UITableView.

What are all the things I need to do to set it up? Based on what I have seen in Apple's documentation, I need to adopt the UITableViewDelegate and UITableViewDataSource protocols. I also read somewhere that I need to inherit from the UIResponder class, but I am not sure.

Is there anything else necessary for setup? Or is it more suitable to use a UITableViewController?

Upvotes: 1

Views: 132

Answers (1)

deekay
deekay

Reputation: 929

As you already noticed, creating whole UITableViewController is an unnecessary overhead.

What you need is just to implement required methods of UITableViewDelegate and UITableViewDataSource protocols. Then instantiate UITableView, set its delegate and data source appropriately, and display it.

Upvotes: 4

Related Questions