我有一个由 nib 文件制成的自定义 UITableViewCell 并包含大 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;
}