I have a subclass of a UITableViewCell. I am trying to adjust the alpha of a whiteLine subview, but the alpha only takes effect once scrolling to an off screen cell. The initial batch of whiteLine subviews display with an alpha of 1.0.
Here’s how I set up the table cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CartCell";
BaseCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[BaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
[cell rowIsOdd:(indexPath.row%2 ? NO : YES)];
return cell;
}
And here’s how I’m setting up whiteLine and altering its alpha within the table cell subclass:
- (void)drawRect:(CGRect)rect
{
self.whiteLine = [[UIView alloc] initWithFrame:CGRectMake(0.0, self.frame.size.height-1.0, self.frame.size.width, 1.0)];
self.whiteLine.backgroundColor = [UIColor whiteColor];
[self addSubview:self.whiteLine];
}
- (void)rowIsOdd:(BOOL)isOdd
{
self.whiteLine.alpha = (isOdd ? 0.7 : 0.3);
}
Could the problem be that I’m using properties? I never know when not to use properties. This definitely is not a property that is accessible outside of this class.
I figured it out. I needed to setup the view in
awakeFromNibinstead ofdrawRect.