开发者

Custom UITableViewCell fast scrolling

I have an UITableView showing custom view cells that I've designed in interface builder. It has quite many buttons and labels and a gradient background, which makes the scrolling performance sloppy, it "lags" every time a new cell loads. I've read the guide from the guy who created Tweetie about fast scrolling, and it says it's best to draw everything manually.

Is there any other way to do this? I want to use my .xib file since it's quite tedious work to draw all those components manually.

This is how the cellForRowAtIndexPath: method is implemented:

- (UITableViewCel开发者_运维问答l *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"ThreadsViewCell";

    ThreadViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil){       
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ThreadViewCell" owner:nil options:nil];

        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[ThreadViewCell class]])
            {
                cell = (ThreadViewCell *)currentObject;
                break;
            }
        }
    }


Complex view hierarchies and alpha blending will always kill your scrolling performance.

You need to either flatten/simplify the view hierarchy, or start working on your CoreGraphics skills.

If you're interested in seeing how much blending you have going on, run (on a device) the "Core Animation" mode in instruments and check the "Color Blended Layers" check box. You want to see as much green as possible, the darker the red, the worse your blending.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜