uitableViewcell 中的 UIImage 会减慢滚动表格的速度
您好,我正在尝试在 Table 的 cell.image 中获取 facebook 用户的个人资料图片。但它减慢了表格视图的滚动速度。然后我使用 异步加载图像链接但我很困惑如何在我的表方法中使用它
- (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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它的速度会变慢,因为每次调用
cellForRowAtIndexPath:
时都会设置image
。仅在if (cell == nil)
块内将图像添加到单元格的 imageView 中。然后你会看到滚动方面的改进。Its slows down because you are setting the
image
every time thecellForRowAtIndexPath:
is called. Add the image to the cell's imageView only inside theif (cell == nil)
block. Then you will see the improvement in scrolling.此代码正在创建所描述的问题...尝试此方法...下载任何图像后,将其保存在文档目录中的任何临时文件夹中(为您的图像命名,以便您可以唯一地识别每个图像).. ..当您必须配置单元格时,每次调用方法 celForRowAtIndexPath 时只需从临时文件夹中获取图像..不要使用
这在这里没有意义,因为您没有使用它(你只是使用它的
.image
属性)....如果可能的话,还可以收集viewDidLoad
中的所有数据,这样您就可以进一步提高性能This code is creating the described problem ..... try this approch ... once any image is downloaded save it in any temp folder in document directory(make name of ur image such that you can identify each of them uniquely)....and when you have to configure the cell just take the image form tha temp folder every time the method
celForRowAtIndexPath
is called .... dont useThis make no sence here as you are not using it (you are just using its
.image
property) .... also if possible collect all you data inviewDidLoad
in that way you can further improve the performance您确定是异步图像导致问题吗?评论异步图像部分,看看可能是 FbGraphResponse 部分才是真正的原因。
我发现您每次都为图形响应创建图像,这可能会导致速度减慢。
Are you sure it's the async image causing problems? Comment the async image part, and see maybe it's the FbGraphResponse part the actual cause.
I see that you're creating an image each time for the graph response and this can cause a slow-down.