异步加载的图像
答
你是说在后台下载图像?
本教程由杰夫·拉马什是一个很好的解决方案 - http://iphonedevelopment.blogspot.com/2010/05/downloading-images-for-table-without.html
答
。利用EGOImageView的假设你想在的UIImageView显示下载的图像,它真的很容易(只是一个占位符图像初始化和设置要下载的图像的URL)。
http://developers.enormego.com/view/what_if_images_on_the_iphone_were_as_easy_as_html
如果你不想显示图像,而只是希望异步下载,使用EGOImageLoader的。
只要确保你的类符合EGOImageLoaderObserver协议并实施2委托方法,你就大功告成了......
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
imageLoader = [EGOImageLoader sharedImageLoader]; // ivar, so we can remove the observer in the dealloc ...
}
return self;
}
- (void)dealloc
{
[imageLoader removeObserver:self];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlString = @"http://www.wimwauters.be/wp-content/uploads/2011/01/steve-jobs.jpg";
NSURL *url = [NSURL URLWithString:urlString];
[imageLoader loadImageForURL:url observer:self];
}
#pragma mark - EGOImageLoaderObserver
- (void)imageLoaderDidLoad:(NSNotification*)notification
{
NSDictionary *userInfo = [notification userInfo];
UIImage *theImage = [userInfo objectForKey:@"image"];
// do something with the image, e.g. display it in an ImageView ...
}
- (void)imageLoaderDidFailToLoad:(NSNotification*)notification
{
NSDictionary *userInfo = [notification userInfo];
NSError *error = [userInfo objectForKey:@"error"];
if (error)
{
// handle the error
}
}
你能解释一下它花费更多一些的话吗? – gd1 2011-04-30 07:56:42
我得到json图像我想加载图像,但非常耗时,所以我不知道如何使用异步方法来加载图像 – user732177 2011-04-30 08:00:59