使用Afnetworking获取UIImageView并将其放入数组中 [英] Get UIImageView using Afnetworking and put it in an array
问题描述
正如标题所说,我需要获取图像并将其放入数组中。
As the title says, i need to get the image and put it in an array.
UIImageView *myImage = [[UIImageView alloc] init];
[myImage setImageWithURL:[NSURL URLWithString:@"http://host.com/images/1/1.png"] placeholderImage:[UIImage imageNamed:@"page3.png"]];
[items addObject:myImage];
问题是在加载图像时,代码会继续,并且没有任何内容放入数组中,实际上我猜一个空的UIImageView被插入。
the problem is that while the image is being loaded, the code continues and nothing gets put in the array, actually I guess an empty UIImageView gets inserted.
如何修复此问题?
在旁注上我使用iCarousel来显示图像,在数据源中,它获取图像数组并显示它们。我能以某种方式修改iCarousel吗?
On a side note I am using iCarousel to display images, in the data source it gets the images array and shows them. Can i modify iCarousel somehow?
提前致谢。
推荐答案
您可以使用setImageWithURLRequest方法提供成功消息,或者在完成后执行UI更新,例如使用以下方法:
You can use the setImageWithURLRequest method to give a success message or execute the UI update when it has finished for example using the following method:
- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
placeholderImage:(UIImage *)placeholderImage
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
这是一个例子(未经测试)
Here is an example (not tested)
[image setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"host.com/images/1/1.png"]] placeholderImage:[UIImage imageNamed:@"page3.png"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
//reload data here
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
//handle errors here
}
这篇关于使用Afnetworking获取UIImageView并将其放入数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!