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