我对tableview有问题,在实现了带有uiblurview的顶部栏后,在iphone5滚动的表视图上滞后,需要20-25%的cpu,然后添加模糊视图。效果很好。期待任何性能上的帮助
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell%li%i",(long)indexPath.row,cellvar]];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"Cell%li%i",(long)indexPath.row,cellvar]];
if ([self.obrazki count]>0) {
CGRect imageFrame = CGRectMake((cell.frame.size.width/tableViewOffset)-(tableView.frame.size.width*0.92/2), 10, tableView.frame.size.width*0.92, tableView.frame.size.width*0.92);
UIImageView * image = [[UIImageView alloc] initWithFrame:imageFrame];
image.layer.masksToBounds = YES;
image.layer.cornerRadius = 25;
[image setImage:[self.obrazki objectAtIndex:indexPath.row]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
image.backgroundColor = [UIColor clearColor];
[cell addSubview:image];
cell.backgroundColor = [UIColor clearColor];
UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView= [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = CGRectMake((cell.frame.size.width/tableViewOffset)-(tableView.frame.size.width*0.92/2)-0.5, 9,tableView.frame.size.width*0.92+1,35);
CAShapeLayer * maskLayer = [CAShapeLayer layer];
maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: visualEffectView.bounds byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: (CGSize){25.0, 25.0}].CGPath;
visualEffectView.layer.mask = maskLayer;
visualEffectView.layer.masksToBounds = YES;
[cell addSubview:visualEffectView];
UILabel *likeCount = [[UILabel alloc] initWithFrame:CGRectMake((cell.frame.size.width/tableViewOffset)-(tableView.frame.size.width*0.92/2)+distanceFromStart, 4,tableView.frame.size.width*0.92,35)];
likeCount.text = [NSString stringWithFormat:@"%@",[imagesLikes objectAtIndex:indexPath.row]];
likeCount.backgroundColor = [UIColor clearColor];
likeCount.tintColor = [UIColor blackColor];
likeCount.font = [UIFont fontWithName:@"AppleSDGothicNeo-Thin" size:20];
[visualEffectView addSubview:likeCount];
CGRect imageLikeFrame = CGRectMake(likeCount.frame.origin.x-20, likeCount.frame.origin.y+7.5, 16, 16);
UIImageView * imageLike = [[UIImageView alloc] initWithFrame:imageLikeFrame];
[imageLike setImage:[UIImage imageNamed:@"like.png"]];
imageLike.layer.masksToBounds=YES;
imageLike.backgroundColor = [UIColor clearColor];
[visualEffectView addSubview:imageLike];
NSLog(@"Generating:%i",indexPath.row);
}
}
// NSLog(@"LoadingOnView:%i",indexPath.row);
return cell;
}发布于 2014-12-01 09:09:40
您正在为每一行创建一个单元格(UITableViewCell的实例),而不是重用已退出队列的单元格。"dequeueReusableCell...“是否有表现上的原因。使用它来排线和重用其他行的单元格。
对所有单元格使用常量单元格标识符,只需修改每一行的单元格即可。也就是说,改变图像或文本。但是,如果您想要提高性能,可以重用这些单元。这是第一件事。然后,告诉我们性能是否足够,或者您是否需要更多的优化。
https://stackoverflow.com/questions/27223733
复制相似问题