I’m trying to use a UITableView without using a nib and without using a UITableViewController.
I have added a UITableView instance to a UIViewController Like So
mytable = [[UITableView alloc] initWithFrame:CGRectMake(22, 207, 270, 233)];
[mytable setDelegate:self];
[self.view mytable];
Also I have added the following table view methods to my UIViewController (cut for brevities sake)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
I am getting a warning saying that my UIViewController does not implement UITableView delegate protocol.
Whats the correct way to tell the table view where its delegate methods are?
(This is my first attempt at trying to use a UITableView without selecting the UITableTableview controller from the new file options)
You need to conform your class to the
UITableViewDelegateandUITableViewDataSourceprotocols. (cellForRowAtIndexPath:is in theUITableViewDataSourceprotocol )Do this by using angle brackets in your class interface definition:
The reason why you are getting this warning now and not before when you were using a
UITableViewControlleris becauseUITableViewControlleralready conforms to these protocols.So, in essence a
UITableViewControlleris just a class that conforms toUITableViewDelegateandUITableViewDataSource, and has aUITableViewinstance member.That’s pretty much it.
Of course, if you’re not already subclassing
UITableViewController, then you need to manually setup thedataSourceanddelegateof theUITableView: