views:

31

answers:

1

My UITableViewCell is being transparent when it's not supposed to be. My table 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;
A: 

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.

Mugunth Kumar
Doesn't help. Actually I started out with initwithstyle, but that didn't work, so I went back to some older code to see if that worked. In any case, it doesn't seem to affect it.
David Liu
then add cell.backgroundcolor = [UIColor clearColor];
Mugunth Kumar
Doesn't do anything. Did you mean whiteColor? Sadly that doesn't work either. In general, the entire text label is messed up and doesn't follow regular subview rules or something. I tried instead setting the backgroundView.backgroundColor to white, and that will end up coloring the borders white, but everything within the label's bounds act as like a window, revealing the background of table underneath.I basically circumvented the whole situation by not dealing with the tablecell's textLabel, and added a UILabel of my own. Very stupid and hackish though. Makes no sense.
David Liu