Reputation: 5879
i'm having 2 problems using uitableview custom headers:
1) The bigger one is that custom headers are slowing down a lot the scrolling of the list on a real iPhone 3G with 3.1.3, while remains perfect on the simulator or on a real iPad. This is the code i'm using:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[HeaderView alloc] init];
headerView.alpha = 0.7;
UITextView *label = [[UITextView alloc] initWithFrame:CGRectZero];
label.textColor = [UIColor whiteColor];
switch (section) {
case 0:
label.text = @"Mattina";
break;
case 1:
label.text = @"Pomeriggio";
break;
case 2:
label.text = @"Sera";
break;
default:
label.text = @"";
break;
}
[headerView addSubview:label];
return headerView;
}
2) Using the above code the title label is not showing... where's the error?
Thanks!
Upvotes: 2
Views: 478
Reputation: 5879
The slowness was caused by a leak. The solution was simply to set the autorelease on the headerView
object:
UIView *headerView = [[[HeaderView alloc] init] autorelease];
Upvotes: 0
Reputation: 10333
I see two problems in this:
Why are you setting label's frame to CGRectZero? It doesn't have the autoresizing property set by default, so it won't stretch to fit Headerview. I'd set the width and height explicitly, just to be sure, but this might do the trick:
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Why are you using UITextView instead of UILabel? It's not widely known, but UITextView has some issues with displaying content after being placed on scrollable views. It does not always refresh properly. Moreover, it's an overuse, I would personally find it counterintuitive to be able to scroll a view within another scroll view i.e UITextView within UITableView.
Upvotes: 1
Reputation: 10011
@Abramodj i think you need to do
[label setBackgroundColor:[UIColor clearColor]];
Upvotes: 0