24

What is the difference between dragging a Table View Controller into the storyboard vs dragging a UI View Controller and dragging a Table View inside that in xCode?

I know how to populate a table view controller in code.

- (UITableViewCell *)tableView:(UITableView *)tableView 
                     cellForRowAtIndexPath:(NSIndexPath *)indexPath;

How do I populate a table view within a UI View Controller? What custom class do I delegate to the UI View? I cannot seem to put a tableViewController on it as it is only a ViewController with a table view...

I'd like to know this because I'd like to have objects other than the table in that view (i.e. a section of the view is for the table and the other section contains a label, an image, and a button.)

lorenzoid
  • 1,812
  • 10
  • 33
  • 51

3 Answers3

33

Populating a UITableView inside of a UIViewController is no different than populating a UITableView inside of a UITableViewController. You just have to make sure you implement the required datasource and delegate methods. You also need to be sure to assign the UIViewController as the delegate and the datasource for that UITableView.

If you want objects other than the table, then you should us a UIViewController. In fact, I rarely use the UITableViewController any more just in case I need to add other objects.

sosborn
  • 14,676
  • 2
  • 42
  • 46
  • 1
    This is a good tutorial: http://www.iosdevnotes.com/2011/10/uitableview-tutorial/ – sosborn Mar 14 '12 at 00:44
  • What is the difference tho, I cant find an answer for that – meda Feb 07 '14 at 23:24
  • 7
    @meda - a UITableViewController assumes that the only view available is a UITableView. Adding more views to that hierarchy is not fun. A UIViewController on the other hand gives you a lot more flexibility, and the initial setup is not that difficult. – sosborn Feb 09 '14 at 21:38
  • 1
    What about performance of the `UITableView` if there is a lot of components in `UITableViewCell` ? – AykutE Sep 11 '15 at 11:12
9

I found another difference too . While using a UITableViewController , which has UIScrollView in it , the view scrolls up when keyboard moves up . This doesn't happen with UIViewController as you need separate methods for View scrolling up and down .

You can also take a look at this
https://stackoverflow.com/a/14465669/5553647

Community
  • 1
  • 1
user5553647
  • 199
  • 2
  • 13