0
NSURL *url =[NSURL URLWithString:
@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"];
連載如下存儲圖像到緩存,以避免從URL中的tableview頻繁加載
(void)connectionDidFinishLoading{
NSDictionary *allDict = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSArray *loans = [allDict objectForKey:@"loans"];
countryArray = [[NSMutableArray alloc] init];
for (NSDictionary *diction in loans) {
Country *countryObj = [[Country alloc]init];
NSString *sector = [diction objectForKey:@"sector"];
countryObj.sector = sector;
NSDictionary *imageID = [diction objectForKey:@"image"];
NSString *img = [imageID objectForKey:@"id"];
countryObj.idValue=img;
NSString *activity = [diction objectForKey:@"activity"];
countryObj.activity = activity;
NSString *name = [diction objectForKey:@"name"];
countryObj.name = name;
NSDictionary *con = [diction objectForKey:@"location"];
NSString *world = [con objectForKey:@"country"];
countryObj.country= world;
NSString *towname = [con objectForKey:@"town"];
countryObj.down=towname;
[countryArray addObject:countryObj];
}
}
做這既有圖像和數據。我需要將圖像存儲到緩存中。
用戶SDWebimage或AFN負載圖像異步 –
這是一個請求API,你需要初始發送請求到服務器,並需要serlize響應後,遵循nitin gohel評論 –
我已經做了序列化,我已經將它加載到tableview中。但事情每次都需要時間從url加載。因爲我是新鮮的,我不知道SDWebimage/AFN – Muthukumar