iphone使用自定义单元格滚动tableview太慢 [英] iphone Scrolling of tableview with custom cells is too slow
问题描述
在iPhone上部署应用程序时遇到了这个问题,在模拟器上未检测到。
I have this problem when deploying my application on iphone, which wasn't detected on the simulator.
这是cellforrow的代码...
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=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 ms的时间。问题出在别的地方,我猜想有一种优化此代码的方法,我想知道自定义单元格的影响,它只是具有与此ViewController链接的带有标签和文本字段的单元格。
任何想法。
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.
推荐答案
好吧,主要的性能问题是围绕contentview子视图的角落。
使用QuartzCore:
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.
这篇关于iphone使用自定义单元格滚动tableview太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!