开发者

iphone Scrolling of tableview with custom cells is too slow

I have this problem when deploying my application on iphone, which wasn't detected on the simulator.

this the code of the cellforrow...

    - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSLog(@"beginning cellforRowAtIndexPath for section %d, and cell %d",[indexPath indexAtPosition:0],[indexPath indexAtPosition:1]);

    static NSString *MyIdentifier = @"MyIdentifier";
    NSString *fieldTitle;
    NSString*fieldDescription;
    [_stopWatch start];
    [PersonalSection GetField:&fieldTitle AndValue:&fieldDescription UsingIndexPath:indexPath AndPersonalInformation:_personalInfo];


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"ViewContent" owner:self options:nil];
        cell = tvCell;
        self.tvCell=nil;

        ((UILabel*) [cell.contentView viewWithTag:1]).layer.cornerRadius=11;
        ((UILabel*) [cell.contentView viewWithTag:2]).layer.cornerRadius=11;
    }


    UILabel*mainLabel=(UILabel*) [cell.contentView viewWithTag:1];
    mainLabel.text=fieldTit开发者_如何学Gole;
    //mainLabel.textColor = [UIColor colorWithRed:0.745 green:0.116 blue:0.176 alpha:1.0];

    UILabel*detailLabel=(UILabel*)[cell.contentView viewWithTag:2];
    detailLabel.text=fieldDescription;
    [_stopWatch stop];
    NSLog(@"---------End cellforRowAtIndexPath");

    return cell;
}

the rest is for sections and it's like return 3 or 5 no real bottleneck there. so i'm wondering what's slowing it so much. now the data fetching "[PersonalSection GetField:&fieldTitle..." is rather fast, it takes on the iphone maximum 0.1 ms. The problem is somewhere else, i'm guessing there's a way for optimizing this code, and i'm wondering about the custom cell influence it's only a cell with label and textfield linked to this ViewController. Any ideas.


When you create the cell you're setting the identifier to @"cell" but when you dequeue it you're looking for @"MyIdentifier". It looks like you're recreating the cell every time though this.


Ok, the main performance issue was rounding the corners of the subviews of the contentview. using QuartzCore:

#import <QuartzCore/QuartzCore.h>
((UILabel*) [cell.contentView viewWithTag:1]).layer.cornerRadius=11;

I removed those and decreased the sizes of the controls to fit inside the cell of a sectioned table. and now they look round but the textfield and label are not. this has fixed my scrolling performance noticeably. Thank you all for your help.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜