UITableViewCell is transparent when not supposed to be
My UITableViewCell is being transparent when it's not supposed to be. My ta开发者_StackOverflow中文版ble view has a background color and it shows through the table cell, even though they're supposed to be opaque. I'm not sure why this is.
Relevant code:
UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:emptyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:emptyIdentifier] autorelease];
}
cell.textLabel.text = @"Empty";
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.backgroundColor = [UIColor whiteColor];
return cell;
I believe it's because of the CGRectZero. Try using initWithStyle and use one of the system styles. http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableViewCell/initWithStyle:reuseIdentifier:
Nevertheless, initWithFrame is already deprecated.
in IB, click on the uitableviewcell, then check the "clip subviews" property.
精彩评论