I have a UIViewController
that I want to use to implement the methods of UITableViewDataSource
on. I have this header, FriendsController.h
:
#import <UIKit/UIKit.h>
@interface FriendsController : UIViewController <UITableViewDataSource>
@end
Edit: now updated the @interface
declaration to:
@interface FriendsController : UIViewController <UITableViewDataSource, UITableViewDelegate>
and this implementation, FriendsController.m
:
#import "FriendsController.h"
@implementation FriendsController
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSLog(@"CALLED .numberOfRowsInSection()");
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"CALLED cellForRowAtIndexPath()");
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"FriendCell"];
cell.textLabel.text = @"Testing label";
return cell;
}
@end
When run this gives me a '-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x81734d0
'. Can anyone see if there is something wrong with my implementation/declaration of .numberOfRowsInSection()
?
Edit: I've added a technique for method listing from here and run the view 'unconnected', it outputs the following list:
[<timestamp etc>] Method no #0: tableView:numberOfRowsInSection:
[<timestamp etc>] Method no #1: tableView:cellForRowAtIndexPath:
[<timestamp etc>] Method no #2: numberOfSectionsInTableView:
[<timestamp etc>] Method no #3: tableView:didSelectRowAtIndexPath:
[<timestamp etc>] Method no #4: viewDidLoad
Post scriptum: Both @ThisDarkTao and @Pei got it right, as can be seen in my previous question documenting the visual parts, here.