How to extend function of UIImageView that asynchronous loading image using ASIHTTP?
I try to do TableViewController and TableCell have an image.
While the row can load image of web, I directly call my own custom function of UIImageView.
And then I just set i开发者_如何学Gomage and show it while requestDidFininshed.
But now, I have a problem that this method is happen
Error Domain=ASIHTTPRequestErrorDomain Code=6 "Unable to start HTTP connection" UserInfo=0x6a48880 {NSLocalizedDescription=Unable to start HTTP connection}
So I need somebody help me to solve this problem. Thanks.
// UIImageView+AsyncLoadImage.h
#import <Foundation/Foundation.h>
@interface UIImageView (AsyncLoadImage)
-(void)asyncLoadWithNSURL:(NSURL *)url;
@end
// UIImageView+AsyncLoadImage.m
#import "UIImageView+AsyncLoadImage.h"
#import "ASIHTTPRequest.h"
@implementation UIImageView (AsyncLoadImage)
-(void)requestFinished:(ASIHTTPRequest *)request
{
NSData *data = [request responseData];
[self.image initWithData:data];
}
-(void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(@"error: %@", [error description]);
}
-(void)asyncLoadWithNSURL:(NSURL *)url
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
@end
There's no obvious problem in the code you included in your question.
The error is that ASIHTTPRequest is unable to start the HTTP connection - the most likely reasons are that there is something wrong with the URL, something wrong with the server or your device doesn't have a network connection.
精彩评论