使用RestKit从NSURLasynchronous加载图像
在RestKit
是否有包装器或某种内置function来使用callback或块asynchronous加载来自NSURL
的UIImage
? 我无法在RestKit
文档中find这样的方法。 如果没有,尽可能使用 RestKit
从NSURL
实现延迟加载的asynchronous映像有什么好的策略?
使用RestKit,你可以使用RKRequest
来加载图像的数据,例如:
RKRequest* request = [RKRequest requestWithURL: url]; request.onDidLoadResponse = ^(RKResponse* response) { UIImage* image = [UIImage imageWithData: response.body]; // do something interesting with the image }; request.onDidFailLoadWithError = ^(NSError* error) { // handle failure to load image } [imageLoadingQueue addRequest: request];
请注意,即使在onDidLoadResponse
情况下,你可能想检查response
,以确保数据的types是你所期望的。 上面使用的图像加载队列可以像这样创build:
imageLoadingQueue = [RKRequestQueue requestQueueWithName: @"imageLoadingQueue"]; [imageLoadingQueue start];
不知道一个RestKit解决scheme,但SDWebImage是一个库,可以让你轻松地加载图像asynchronousUIImageView添加一个类别,所以你只需要写这个(例如):
[myImageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
- 崩溃在iPhone开发下载asynchronous图像
- 观察asynchronous请求
- 简单的asynchronous图像下载UIImage视图
- 把sharedLoader函数转换成一个正常的函数
- 从摄像头获取所有图像asynchronous
- 当我在asynchronous重载数据期间滚动时,为什么我的UITableView失去stream动性?
- parsing消息应用程序,需要find一种方法来延迟代码执行,直到deleteAllInBackground完成执行。 包括详细的代码
- 使stringWithContentsOfURLasynchronous – 是否安全?
- 迅速closures和asynchronous任务