1
votes

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 image 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
1

1 Answers

1
votes

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.