4

I am experiencing a weird visual glitch whereby reloading a section of my UITableView is causing the semitransparent header view (alpha=0.25) to flash briefly darker, as if it were adding another copy of the header view on top of the old one and then removing the previous one.

My header view itself is a UIImageView generated dynamically, however I've simplified it to just a UIView with a backgroundColor of [[UIColor blackColor] colorWithAlphaComponent:0.25] and it still exhibits the problem:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.width, kModPopHeaderHeight)];
    view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.25];
    view.opaque = NO;
    return view;
}

As you can see I'm setting opaque to NO, but that doesn't have any effect. I've also tried keeping a dictionary of previously generated views indexed on the section and returning the existing view if it has already been created (to test my theory of it showing two views overlapping) but that also surprisingly had no effect. It flashes regardless.

Note that if I set the alpha of the header to 1.0 there is no visual glitch, so it clearly has something to do with the transparency. It also doesn't happen on every tap (reload), but most. I just can't figure out what I need to change in order to get it to draw properly. Any advice would be appreciated.

devios1
  • 36,899
  • 45
  • 162
  • 260

1 Answers1

1

Ok I actually managed to solve this myself, based on my idea of keeping an index of existing headerViews. What I tried the first time was to call [existingView removeFromSuperview], but that didn't work at all.

Instead, I changed it to existingView.hidden = YES and the flashing magically went away! So there you go. While I can't explain why that works and removeFromSuperview doesn't, if anyone else is running into this problem try hiding the existing view before returning the new view.

devios1
  • 36,899
  • 45
  • 162
  • 260