UITableViewController setting delegates and datasource
Posted
by
the_great_monkey
on Stack Overflow
See other posts from Stack Overflow
or by the_great_monkey
Published on 2010-12-31T08:43:46Z
Indexed on
2010/12/31
8:54 UTC
Read the original article
Hit count: 211
Hi iOS gurus, I'm a little bit confused about UITableViewController... As far as I concern they are typically the delegate and datasource of the UITableView (although it can be made such that they are different).
However in some cases, like when embedding a UITableViewController in a UITabBarViewController in Interface Builder, we initiate our table view controller in IB. Therefore in my understanding, the default initialiser is being called.
But in this case, I have this piece of code:
@interface Settings : UITableViewController {
}
And in the IB I see that the delegate and datasource of the UITableView is hooked up to this class. My question is, why is it that we don't need to explicitly say that it is following:
@interface Settings : UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
}
And in the .m file:
- (void)viewDidLoad {
[super viewDidLoad];
[tableView setDelegate:self];
[tableView setDataSource:self];
}
I have indeed stumbled upon some cases where I have to explicitly code the above a few times to make something work. Although it is still a mystery for me as of why it is needed...
© Stack Overflow or respective owner