I'm testing UITableView with a custom TableViewCell. The custom cell is designed in a .xib file and has its own class called cell, which is a subclass of UITableViewCell:
Cell.m
#import "Cell.h"
@implementation Cell
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
return self;
}
@end
The ViewController class has the UITableView called table in it. It is also Delegate and Datasource for it. Both is set in the Storyboard. Its code looks like this:
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.table registerClass:[Cell class] forCellReuseIdentifier:@"cell" ];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [self.table dequeueReusableCellWithIdentifier:@"cell"];
return cell;
}
@end
If I run the app, I can see the table and it has the right number of cells. But the custom cell is not shown. Each cell of the table is just white.
I read a couple of post on issues like this but no one helped me. Different Tutorials say it should work like this but it doesn't. I think there may is a stupid mistake in it. Thanks for your help.