Optimization headers for UITableView?

Posted by Pask on Stack Overflow See other posts from Stack Overflow or by Pask
Published on 2010-05-16T23:22:01Z Indexed on 2010/05/16 23:30 UTC
Read the original article Hit count: 309

Filed under:
|
|

I have an optimization problem for the headers of a table with plain style. If I use the standard view for the table (the classic gray with titles set by titleForHeaderInSection:) everything is ok and the scrolling is smooth and immediate.

When, instead, use this code to set my personal view:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    return [self headerPerTitolo:[titoliSezioni objectAtIndex:section]];
}

- (UIImageView *)headerPerTitolo:(NSString *)titolo {

    UIImageView *headerView = [[[UIImageView alloc] initWithFrame:CGRectMake(10.0, 0.0, 320.0, 44.0)] autorelease];
    headerView.image = [UIImage imageNamed:kNomeImmagineHeader];
    headerView.alpha = kAlphaSezioniTablePlain;

    UILabel * headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor whiteColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:16];
    headerLabel.frame = CGRectMake(10.0,-11.0, 320.0, 44.0);
    headerLabel.textAlignment = UITextAlignmentLeft;
    headerLabel.text = titolo;

    [headerView addSubview:headerLabel];

    return headerView;
}

scrolling is jerky and not immediate (sliding the finger on the screen does not match an immediate shift of the table).

I do not know what caused this problem, maybe the fact that every time the method viewForHeaderInSection: is called, the code runs to create a new UIImageView.

I tried many ways to solve the problem, such as creating an array of all the necessary view: apart from more time spent loading at startup, there is a continuing problem of low reactivity of the table.

've Attempted by reducing the size of UIImageView positioned from about 66 KB to 4 KB: not only has a deterioration in quality of colors (which distorts a bit 'original graphics), but ... the problem persists!

Perhaps you have suggestions about it, or know me obscure techniques that enable me to optimize this aspect of my application ...

I apologize for my English, I used Google for translation.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode