【发布时间】:2011-06-25 10:10:03
【问题描述】:
我尝试做 TableViewController 和 TableCell 有一个图像。
虽然该行可以加载网页图片,但我直接调用了自己的UIImageView自定义函数。
然后我只是设置图像并在 requestDidFininshed 时显示它。
但是现在,我有一个问题是这种方法发生了
Error Domain=ASIHTTPRequestErrorDomain Code=6 "无法启动 HTTP 连接" UserInfo=0x6a48880 {NSLocalizedDescription=无法启动 HTTP 连接}
所以我需要有人帮我解决这个问题。谢谢。
// 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
【问题讨论】:
标签: ios asynchronous uiimageview loading asihttprequest