我正在開發一個圖像下載應用程序。圖像大小不同。我想在圖像下載時下載圖像異步並更新表格視圖。還需要在一段時間間隔清除緩存。下載圖像製作和更新表格視圖
請告訴我如何實施。我看過SDwebimagecache,但它在下載圖像時崩潰了。
我正在開發一個圖像下載應用程序。圖像大小不同。我想在圖像下載時下載圖像異步並更新表格視圖。還需要在一段時間間隔清除緩存。下載圖像製作和更新表格視圖
請告訴我如何實施。我看過SDwebimagecache,但它在下載圖像時崩潰了。
我希望它能幫助你。我在所有(ARC)項目中使用SDWebImage。
使用:
添加您的ViewController:#import "UIImageView+WebCache.h"
[yourImageView setImageWithURL:[NSURL URLWithString:@"ImageUrl"]];
需要和的ImageIO添加MapKit到項目中。如果您沒有添加
爲了做到這一點:
單擊該項目在項目導航器頂部在Xcode
選擇「構建階段」選項卡。
打通「鏈接二進制與圖書館」框。
點擊'+'。
添加MapKit和ImageIO的框架。
我已經使用了核心數據和AFNetworking來實現同樣的事情,在下面找到我的代碼
UserBasicInfo* userBasicInfo = [[UserBasicInfo findByAttribute:@"userId" withValue:@(chatUser)] objectAtIndex:0];;
if (userBasicInfo.userImage == nil) {
__weak LGMessageBoxCell *weakCell = cell;
[cell.userImage setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:userBasicInfo.imageUrl]]
placeholderImage:[UIImage imageNamed:@"facebook-no-user.png"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
weakCell.userImage.image = image;
[weakCell setNeedsLayout];
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
UserBasicInfo* userBasicInfo = [[UserBasicInfo findByAttribute:@"userId" withValue:@(chatUser) inContext:localContext] objectAtIndex:0];
userBasicInfo.userImage = UIImagePNGRepresentation(image);
} completion:^(BOOL success, NSError *error) {
NSLog(@"%@",[error localizedDescription]);
}];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
}];
} else {
cell.userImage.image = [UIImage imageWithData:userBasicInfo.userImage];
}
http://ezekiel.vancouver.wsu.edu/~wayne/yellowjacket/YellowJacket.zip嘗試THI – wasim