So I have a cell loaded directly from a nib file:
NSArray *cellContents = [[NSBundle mainBundle] loadNibNamed:@"ResultsTableViewCell" owner:self options:nil];
cell = [cellContents objectAtIndex:0];
In the nib file, there are a UITableViewCell and Two UIViews, each with its own subviews. Strucuture:
-TableViewCell
Label 1
Label 2
-UIView A
UIView a
UIView b
UIImageView c
UIImageView d
-UIView B
UIView e
UIView f
UIImageView g
UIImageView h
So the UIView A is connected to the backgroundView property for the UITableViewCell, the UIView B is connected to selectedBackgroundView property.
Problem:
So why A shows up fine as the background for the cell with all it’s subviews, and the UIImageViews in B works fine, but the UIViews in B simply doesn’t show up however I change it? Thanks!
Here’s what I found my case. When I logged the RGB and alpha of the UIView’s background color, I found that they were all getting set to 0 when the cell was selected:
Initially, nothing is selected. Tap a row in the table and the log shows:
and my subview does not appear (Note Alpha=0). Funny because when I logged viewE.alpha, it showed it was 1.
Tap the row again to deselect it:
That’s what I expect.
My table cell is a custom UITableViewCell. So in my custom UITableViewCell class I added this code:
Now the subview viewE appears when the cell is selected.
It seems like the code here is compensating for a condition that should not have existed in the first place, but it works!