我的自定义 uitableviewcell 非常适合在 iOS7 中滚动



我有一个自定义的UITableViewCell,它由nib文件制成,包含大图像视图(使用SDWebImage),OHAttributedLabel和5-6 UILabel。

滚动在iOS6中是正常的并且相当快,但是在iOS7中,结果证明它非常慢且滞后。

我试图删除笔尖文件中的一些元素,并注意到当具有大图像视图(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;

}

我对 iOS 7 上的表格滚动性能产生了巨大的性能影响,我将其追踪到以下代码行:

[UISearchBar appearance].backgroundColor = [UIColor whiteColor];

事实证明,这行代码无论如何都没做任何事情 - 当我自定义iOS 7应用程序的外观时,它是错误地输入的。

这一定是 SDK 中的错误,但通过删除此行并重新运行我的应用程序,我的滚动性能自行解决 - 这都是应用程序中的滚动视图。它一定是在主运行循环上做一些窃取 CPU 周期的事情......我不知道这是否有意义。

无论如何。。。您可以随时检查并查看是否有任何外观代码,并暂时将其注释掉以找出影响您性能的原因。

您可以尝试使用常规UILabel。 iOS 6 和 7 支持开箱即用NSAttributedString。在iOS 6中,它使用WebKit,但在iOS 7中它使用Text Kit。iOS 7版本的UILabel应该得到显着优化。

最新更新