Iphone UITableView速度慢,即使只有几个对象?

Iphone UITableView速度慢,即使只有几个对象?,iphone,iphone-sdk-3.0,uitableview,Iphone,Iphone Sdk 3.0,Uitableview,这有什么原因吗?我只设置了几个对象,所以我几乎看不出它为什么会滞后。它会跳,不是我的手机,因为设置应用程序工作正常。我以为你不应该像现在这样设置手机高度。我认为应该实现heightForCellAtIndexPath方法,该方法可能没有100%正确的名称,它会询问您的代表每个单元格的高度。我觉得如果没有采取正确的方式,我已经听说过性能问题。伊姆霍 如果我是你,我会尝试做的第一件事就是注释掉所有与图像相关的代码,看看表格的速度是否大幅提高。我以为你不应该像现在这样设置单元格高度。我认为应该实现he

这有什么原因吗?我只设置了几个对象,所以我几乎看不出它为什么会滞后。它会跳,不是我的手机,因为设置应用程序工作正常。

我以为你不应该像现在这样设置手机高度。我认为应该实现heightForCellAtIndexPath方法,该方法可能没有100%正确的名称,它会询问您的代表每个单元格的高度。我觉得如果没有采取正确的方式,我已经听说过性能问题。伊姆霍


如果我是你,我会尝试做的第一件事就是注释掉所有与图像相关的代码,看看表格的速度是否大幅提高。

我以为你不应该像现在这样设置单元格高度。我认为应该实现heightForCellAtIndexPath方法,该方法可能没有100%正确的名称,它会询问您的代表每个单元格的高度。我觉得如果没有采取正确的方式,我已经听说过性能问题。伊姆霍


如果我是你,我会尝试的第一件事是注释掉所有与图像相关的代码,看看表格的速度是否会大幅提高。

UITableViewCells具有许多子视图,但由于手机渲染每一层的方式,在iPhone上渲染速度较慢

请阅读以下内容:

上述帖子中的信息仍然非常相关和有用,但示例项目下载链接在2011年12月8日被中断。然而,苹果自己的表格视图文档中已经有了用于快速滚动日志的平板表格单元格示例。请查看:

要点是:

iPhone处理Alpha的速度不是很快 子视图的不透明属性应设置为“是” 如果可能,将子视图绘制到单个不透明视图中以获得最佳性能。 显然,带有需要操纵的控件的单元无法展平,因此我认为您只需尝试确保单元子视图不透明即可


我建议的最后一件事是不要每次请求单元格时都分配新对象——这肯定是代码中的一个瓶颈。您应该使用可重用的单元格,并对单元格进行子类化,以便只有在第一次创建单元格时,才会将其字段作为子视图进行分配和添加。后续呼叫应将单元格排成队列,并使用prepareForReuse清除其旧值。

UITableViewCells具有多个子视图,由于手机渲染每个层的方式,在iPhone上渲染速度较慢

请阅读以下内容:

上述帖子中的信息仍然非常相关和有用,但示例项目下载链接在2011年12月8日被中断。然而,苹果自己的表格视图文档中已经有了用于快速滚动日志的平板表格单元格示例。请查看:

要点是:

iPhone处理Alpha的速度不是很快 子视图的不透明属性应设置为“是” 如果可能,将子视图绘制到单个不透明视图中以获得最佳性能。 显然,带有需要操纵的控件的单元无法展平,因此我认为您只需尝试确保单元子视图不透明即可


我建议的最后一件事是不要每次请求单元格时都分配新对象——这肯定是代码中的一个瓶颈。您应该使用可重用的单元格,并对单元格进行子类化,以便只有在第一次创建单元格时,才会将其字段作为子视图进行分配和添加。后续调用应使单元格出列,并使用prepareForReuse清除其旧值。

首先删除该单元格背景。看看这是否有区别。

从移除单元格背景开始。看看这是否有区别。

这里是解决方案,在块内添加要加载的图像,就是这样:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView setRowHeight:100];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
}


#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 100) reuseIdentifier:CellIdentifier] autorelease];

        // For Name/Phone: 
        UITextField *name = [[[UITextField alloc] initWithFrame:CGRectMake(75, 22, 200, 25)] autorelease];
        [name setFont:[UIFont systemFontOfSize:14]];
        [name setPlaceholder:@"John Doe"];
        [name setReturnKeyType:UIReturnKeyDone];
        [name setAutocapitalizationType:UITextAutocapitalizationTypeWords];
        [name setAutocorrectionType:UITextAutocorrectionTypeNo];
        [name setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

        UITextField *phone = [[[UITextField alloc] initWithFrame:CGRectMake(75, 67, 200, 25)] autorelease];
        [phone setFont:[UIFont systemFontOfSize:14]];
        [phone setPlaceholder:@"0412 123 123"];
        [phone setReturnKeyType:UIReturnKeyDone];
        //[phone setKeyboardType:UIKeyboardTypePhonePad];
        [phone setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

        UIImageView *background = [[[UIImageView alloc] initWithFrame:CGRectMake(9, 11, 302, 89)] autorelease];
        background.image = [UIImage imageNamed:@"book-personaldetailsbg.png"];

        // Add to the View
        [cell addSubview:background];
        [cell addSubview:name];
        [cell addSubview:phone];

        // Add actions:
        [name addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 
        [phone addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 

    }

    return cell;
}
优先使用中央总调度。
如果有人愿意,我可以解释,只要发电子邮件到info@tonymedrano.com这里是解决方案,在块内添加要加载的图像,就是这样:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView setRowHeight:100];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
}


#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 100) reuseIdentifier:CellIdentifier] autorelease];

        // For Name/Phone: 
        UITextField *name = [[[UITextField alloc] initWithFrame:CGRectMake(75, 22, 200, 25)] autorelease];
        [name setFont:[UIFont systemFontOfSize:14]];
        [name setPlaceholder:@"John Doe"];
        [name setReturnKeyType:UIReturnKeyDone];
        [name setAutocapitalizationType:UITextAutocapitalizationTypeWords];
        [name setAutocorrectionType:UITextAutocorrectionTypeNo];
        [name setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

        UITextField *phone = [[[UITextField alloc] initWithFrame:CGRectMake(75, 67, 200, 25)] autorelease];
        [phone setFont:[UIFont systemFontOfSize:14]];
        [phone setPlaceholder:@"0412 123 123"];
        [phone setReturnKeyType:UIReturnKeyDone];
        //[phone setKeyboardType:UIKeyboardTypePhonePad];
        [phone setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

        UIImageView *background = [[[UIImageView alloc] initWithFrame:CGRectMake(9, 11, 302, 89)] autorelease];
        background.image = [UIImage imageNamed:@"book-personaldetailsbg.png"];

        // Add to the View
        [cell addSubview:background];
        [cell addSubview:name];
        [cell addSubview:phone];

        // Add actions:
        [name addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 
        [phone addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 

    }

    return cell;
}
优先使用中央总调度。
如果有人愿意,我可以解释,只要发电子邮件到info@tonymedrano.com

在模拟器中工作正常吗?是的,在模拟器中工作完美。也适用于3GS。它的速度并不是太慢以至于应用程序无法使用,它只是有明显的延迟,这真的很烦人——如果固定的话,会有更好的用户体验。估计每个单元格的高度也会有同样的效果,请检查这个主题。它在模拟器中工作正常吗?是的,在模拟器中工作完美。也适用于3GS。它的速度并不是太慢以至于应用程序无法使用,它只是有明显的延迟,这真的很烦人-如果固定的话,会有更好的用户体验。估计每个单元格的高度也会有同样的效果,请检查这个主题好吗,将其替换为-cgloattableview:UITableView*tableView heightForRowAtIndexPath:nsindepath*indepath-它几乎是一样的。是的,它看起来是一样的,但从我所看到的来看
在互联网络中,此方法将减少问题。HeightForcellaIndeXPath对于返回可变高度单元格非常有用,但当您有静态高度单元格时,使用此方法还是在表视图上设置行高属性无关紧要。确定,将其替换为-cgloattableview:UITableView*tableView heightForRowAtIndexPath:nsindepath*indepath-几乎相同。是的,看起来是一样的,但从我在互联网站上看到的情况来看,这种方法会给你带来更少的问题。heightforcellatindepath对于返回可变高度的单元格很有用,但是当你有静态的高度单元格时,不管你是使用这个方法还是在表视图上设置行高属性。是的,自从Loren开始为Twitter工作以来,他的网站已经被清理了。我添加了一个指向苹果文档的链接,其中显示了一个类似的示例。看起来这已经移动到GitHub:Thx~500+行,使用该解决方案,可以快1.1秒。是的,自从Loren开始为Twitter工作以来,他的站点已被清理。我已经添加了一个指向Apple文档的链接,其中显示了一个类似的示例。它看起来已经移动到GitHub:Thx~500+行,使用该解决方案,可以加快1.1秒。