本文介绍了uitableViewcell 中的 UIImage 减慢滚动表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试在 Table 的 cell.image 中获取 facebook 用户的个人资料图片.但它减慢了表格视图的滚动.然后我使用了 图像的异步加载链接但我很困惑如何在我的表格方法中使用它
Hello I am trying to get profile image of facebook user in Table's cell.image. But It slows down Scrolling of Table view.Then I used Asynchronous loading of image link But i am confused how could I use this in my Table's method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.font = [ UIFont fontWithName:@"Arial" size:10.0];
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = [NSString stringWithFormat:@"%@",[(Facebook *)[dummyArray objectAtIndex:indexPath.row] sender]];
cell.detailTextLabel.text =[NSString stringWithFormat:@"%@",[(Facebook *)[dummyArray objectAtIndex:indexPath.row] post]];
NSString *get_string = [NSString stringWithFormat:@"%@/picture",[(Facebook *)[dummyArray objectAtIndex:indexPath.row]senderId]];
AsynchronousImageView *image = [[AsynchronousImageview alloc]init];
[image loadImagewithUrlString:getString];
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:get_string withGetVars:nil];
UIImageView *image_view = [[UIImageView alloc] initWithImage:fb_graph_response.imageResponse];
cell.imageView.image = image_view.image;
[image_view release];
return cell;
}
推荐答案
它变慢了,因为每次调用 cellForRowAtIndexPath:
时你都在设置 image
.仅在 if (cell == nil)
块内将图像添加到单元格的 imageView.然后你会看到滚动的改进.
Its slows down because you are setting the image
every time the cellForRowAtIndexPath:
is called. Add the image to the cell's imageView only inside the if (cell == nil)
block. Then you will see the improvement in scrolling.
这篇关于uitableViewcell 中的 UIImage 减慢滚动表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!