【发布时间】:2015-08-02 08:38:45
【问题描述】:
我正在使用 AFNetworking 从 JSON 提要加载图像。
在这里,当用户第一次打开应用程序时,图像从互联网加载。没关系。
但是当用户从另一个视图返回并再次访问时,在使用应用程序时,图像应该从缓存加载,而不是从互联网加载。
我该怎么做?
- (void)loadDetailData
{
detailPost = nil;
NSString *detailUrl = [NSString stringWithFormat:@"%@", self.Details.firsturl];
AFHTTPRequestOperationManager *detailManager = [AFHTTPRequestOperationManager manager];
[detailManager GET:detailUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
detailPosts = (NSDictionary *)responseObject;
detailPost = [NSMutableArray array];
NSArray *result = [detailPosts objectForKey:@"posts"];
for (NSDictionary *all in result)
{
Categories *newCategory = [Categories new];
NSDictionary *thumbnail_images = [all objectForKey:@"thumbnail_images"];
NSDictionary *mediumImages = [thumbnail_images objectForKey:@"medium"];
newCategory.detailimageUrl = [mediumImages objectForKey:@"url"];
newCategory.title = [all objectForKey:@"title"];
newCategory.mogowebUrl = [all objectForKey:@"url"];
// NSLog(@"%@", newCategory.title);
[detailPost addObject:newCategory];
[self.maintableView reloadData];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [detailPost count];;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier"];
Categories *details = [detailPost objectAtIndex:indexPath.row];
cell.detailTitle.text = details.title;
NSString *imageurl = [NSString stringWithFormat:@"%@", details.detailimageUrl];
NSURL *imgurl = [NSURL URLWithString:imageurl];
[cell.detailImageView setImageWithURL:imgurl placeholderImage:nil];
// [cell addSubview:cell.subView];
cell.layer.masksToBounds = NO;
cell.layer.cornerRadius = 5;
cell.layer.borderColor = [UIColor blackColor].CGColor;
cell.layer.shadowOffset = CGSizeMake(0, 1);
cell.layer.shadowRadius = 2.0;
cell.layer.shadowColor = [UIColor lightGrayColor].CGColor;
return cell;
}
【问题讨论】:
标签: ios afnetworking afnetworking-2