ItemsViewController as the table view's delegate


#1

On page 230 of the 3rd edition, the 3rd paragraph down states that the ItemsViewController (object) is the table view’s delegate. My question is: Is this true because ItemsViewController inherits from TableViewController, which conforms to UITableViewDelegate? I don’t see any explicit setDelegate (as has appeared in earlier chapters), so I’m wondering if the default value for the delegate property is the object that’s doing the conforming. [Apologies for this simple question - I’m trying the best I can to understand the model]


#2

It is not because the ItemsViewController conforms to UITableViewDelegate, that simply says the ItemsViewController CAN be the delegate of a UITableVIew.

Instead, it is because of the default implementation of loadView for ItemsViewController’s superclass, UITableViewController, which looks like this:

- (void)loadView
{
      UITableView *tv = [[UITableView alloc] initWithStyle:[self style]];
      [self setView:tv];
       [tv setDelegate:self];
      [tv setDataSource:self];
}

#3

Thanks, Joe. I’ve looked at the UITableViewController doc, and since loadView: wasn’t there, it apparently is inherited from UIViewController. Please forgive another novice question, but where did you find the code for the default implementation of loadView: that is apparently implemented in UITableViewController? I suppose what I’m really asking, is where would I look to find this, so I could actually verify the setting of the delegate property.


#4

We can’t directly see Apple’s code, but we can infer what is going on from the documentation. In the ‘Overview’ section of the UITableViewController documentation, there is this snippet: