与定制单元的tableview的iphone滚动太慢(iphone Scrolling of tab

2019-09-28 12:05发布

部署我的iPhone应用程序,这是不是在模拟器上检测到时,我有这个问题。

在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=fieldTitle;
    //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;
}

剩下的就是对部中,就像回3或5没有真正的瓶颈在那里。 所以我不知道发生了什么减缓了这么多。 现在获取数据“[PersonalSection getfield命令:fieldTitle ......”是相当快的,它需要在iPhone上最大0.1毫秒。 问题是,别的地方,我猜有优化的代码的方式,我想知道的自定义单元格影响它只能与标签和文本框链接到该视图控制器单元。 有任何想法吗。

Answer 1:

当你创建你,标识设置为@“细胞”,但是当细胞,你出列,这你要找@“MyIdentifier”。 它看起来像你这样,虽然每次都重新创建细胞。



Answer 2:

好吧,主要性能问题是四舍五入的内容查看的子视图的角落。 使用QuartzCore:

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

我除去那些,降低了控制的尺寸,以适应分段表的单元格内。 现在他们回头看,但文本框和标签都没有。 这已明显固定的滚动我的表现。 谢谢大家的帮助。



文章来源: iphone Scrolling of tableview with custom cells is too slow