我有一个自定义UITableViewCell,它由nib文件组成,包含大型imageView(使用SDWebImage),OHAttributedLabel和5-6 UILabel
滚动是正常的,在iOS6中相当快,但在iOS7中,它变得非常缓慢和滞后。
我试图删除nib文件中的一些元素,并注意到在使用大型imageView(SDWebImage)或OHAttributedLabel
时滚动速度非常慢我有什么方法可以改善滚动性能吗?这在iOS6中很好,所以我之前没想到会遇到这个问题(我使用iphone5进行测试)
-(void)viewDidLoad
{
[super viewDidLoad];
//register the nib here for customItemCEll
[self.tableView registerNib:[UINib nibWithNibName:@"customItemCell" bundle:nil] forCellReuseIdentifier:@"customItemCell"];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"customItemCell";
CustomItemCell *cell = (CustomItemCell *)[tableView dequeueReusableCellWithIdentifier:SquakCellIdentifier forIndexPath:indexPath];
customItem *item = [itemsArray objectAtIndex:[indexPath row]];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",[item post] ]];
[attrStr setFontName:@"Helvetica" size:14];
// cell.postLabel is OHAtrributedLabel
cell.postLabel.delegate = self;
cell.postLabel.attributedText = attrStr;
cell.postLabel.text = [item post] ;
//configureHashtage is too ask OHAttributedLabel to make a hashtag link
[cell configureHashtagLabel];
if([item hasImageURLString]){
[cell.postImageView setHidden:NO];
CGFloat yPosition = cell.thumbnailView.frame.origin.y + cell.thumbnailView.frame.size.height+15;
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:14]};
CGRect frameSize = [item.post boundingRectWithSize:CGSizeMake(220, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
yPosition = MAX(yPosition,cell.postLabel.frame.origin.y+frameSize.size.height+20);
[cell.postImageView setImageWithURL:[NSURL URLWithString:[item postImageURLString]] placeholderImage:[UIImage imageNamed:@"image_placeholder.png"] ];
CGRect imageFrame = CGRectMake(10 ,yPosition, 300, 200);
[cell.postImageView setFrame:imageFrame];
[cell.postImageView setClipsToBounds:YES];
cell.postImageView.userInteractionEnabled = YES;
[cell.postImageView setupImageViewerWithImageURL:[NSURL URLWithString:[item postImageURLString]]];
}
else {
[cell.postImageView setHidden:YES];
}
return cell;
}
答案 0 :(得分:0)
我对iOS 7上的表格滚动性能产生了巨大的性能影响,我将其跟踪到这行代码:
[UISearchBar appearance].backgroundColor = [UIColor whiteColor];
事实证明,这行代码无论如何都没有做任何事情 - 当我自定义iOS 7应用程序的外观时,它被错误地放入了。
它一定是SDK中的一个错误,但通过删除此行并重新运行我的应用程序,我的滚动性能自行解决 - 这是应用程序中的所有滚动视图。它必须在主要运行循环上做一些事情,这是在窃取cpu周期...我不知道这是否有意义。
无论如何......你总是可以检查一下,看看你是否有任何外观代码,并暂时将其评论出来,以找出是什么导致了你的表现。
答案 1 :(得分:0)
您可以尝试使用常规UILabel
。 iOS 6和7支持NSAttributedString
开箱即用。在iOS 6中它使用WebKit,但在iOS 7中它使用Text Kit。应该显着优化iOS 7版本的UILabel
。