My simple custom UITableViewCell
subclass does not show its content when selected. When I tap one of the cells, the green view disappears and I only see the cell's red background color. When I select another cell, the content of the previously selected one appear again. Any ideas?
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
self.backgroundColor = [UIColor redColor];
UIView* someView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
someView.backgroundColor = [UIColor greenColor];
[self.contentView addSubview:someView];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
I registered this with in my view controller's `viewDidLoad':
[self.tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"Identifier"];
And here is how I create them:
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Identifier"];
if (cell == nil)
{
cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"Identifier"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}