简体   繁体   English

如何扩展使用ASIHTTP异步加载图像的UIImageView的功能?

[英]How to extend function of UIImageView that asynchronous loading image using ASIHTTP?

I try to do TableViewController and TableCell have an image. 我尝试让TableViewController和TableCell有一个图像。

While the row can load image of web, I directly call my own custom function of UIImageView. 尽管该行可以加载Web图像,但我直接调用了自己的UIImageView自定义函数。

And then I just set image and show it while requestDidFininshed. 然后我只设置图像并在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} 错误域= ASIHTTPRequestErrorDomain代码= 6“无法启动HTTP连接” UserInfo = 0x6a48880 {NSLocalizedDescription =无法启动HTTP连接}

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. 错误是ASIHTTPRequest无法启动HTTP连接-最可能的原因是URL出现问题,服务器出现问题或您的设备没有网络连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM