gpt4 book ai didi

iphone - 绘制单元格时从服务器获取图像

转载 作者:行者123 更新时间:2023-11-29 05:00:29 25 4
gpt4 key购买 nike

为什么我们应该避免在绘制单元格时从服务器加载图像?

在我的应用程序中,我从服务器获取数据,其中也包含图像 URL。现在,我绘制单元格并使用这些图像 URL 从服务器获取图像并绘制它。现在,有时即使图像实际存在于该 URL 中,图像也不会显示,因为我可以通过浏览器看到它。

是否有任何单元格绘图限制可能导致此问题?当我从服务器获取数据时,我应该获取图像吗?

单元格渲染是否发生在实际绘制图像之前。

最佳答案

    NSString *imgUrl = [ImageURLArray objectAtIndex:indexPath.row];

if(imgUrl != nil)
{
NSString * ImagePath;

NetworkManager *manager = [[NetworkManager alloc] init];

ImagePath = [manager GetFile:imgUrl];

[manager release];

manager = nil;

if(ImagePath != nil)

{

UIImage *newImage = [UIImage imageWithData:[NSData dataWithContentsOfFile:ImagePath]];

UIGraphicsBeginImageContext(CGSizeMake(50, 50));

// now redraw our image in a smaller rectangle.
[newImage drawInRect:CGRectMake(25, 10, 30, 30)];

newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

cell.imageView.image = newImage;
}
}
return cell;

希望这能解决您的问题

关于iphone - 绘制单元格时从服务器获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7087036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com