Reputation: 585
I am a beginner, learning how to do tableViews. I followed everything in my book, but my table View is not being populated. Shouldn't it display the word "Testing" for three rows here? My tableview Outlet is connected, and I enabled the delegate and datasource. What am I missing here? After all, I am following a book.
#pragma mark UITableViewDataSource Methods
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"cell"];
if( nil == cell)
{
cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = @"Testing";
return cell;
}
-(NSInteger)tableView: (UITableView *)tv numberofRowsInSection:(NSInteger)section
{
return 3;
}
#pragma mark UITableViewDelegate Methods
-(void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tv deselectRowAtIndexPath:indexPath animated:YES];
}
here is my .h file
#import <UIKit/UIKit.h>
@interface CLViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
Upvotes: 0
Views: 942
Reputation: 540105
You have a typo in your data source method, numberofRowsInSection
should be
numberOfRowsInSection
.
As a consequence, the default implementation of numberOfRowsInSection
is called and
that returns 0
.
Upvotes: 4