#import "TableViewCell.h"
#import "ImageModal.h"
#import "UIImageView+WebCache.h"
@implementation TableViewCell
#pragma mark - 给cell赋值方法
- (void)setCellModal:(ImageModal *)modal
{
[self.pictureImageView sd_setImageWithURL:[NSURL URLWithString:modal.imageUrlString] placeholderImage:[UIImage imageNamed:@"5.png"]];
}
cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"TableViewCell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
ImageModal *modal = self.dataArray[indexPath.row];
[cell setCellModal:modal];
cell.titleLabel.text = modal.title;
return cell;
}
利用第三方 MBProgressHUD
#pragma mark - 网络请求
- (void)loadDataFromNetWork
{
NSString *urlString = @"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php";
[MBProgressHUD showHUDAddedTo:self.mainTableView animated:YES];
JSONAnalysis *json = [[JSONAnalysis alloc] initWithGETRequest:urlString];
[json didFinishUsingBlock:^(id jsonObject) {
NSArray *array = jsonObject[@"events"];
for (NSDictionary *dict in array) {
ImageModal *modal = [[ImageModal alloc] init];
[modal setValuesForKeysWithDictionary:dict];
modal.imageUrlString = dict[@"image"];
[self.dataArray addObject:modal];
[MBProgressHUD hideHUDForView:self.mainTableView animated:YES];
}
[self.mainTableView reloadData];
}];
}
清除缓存
[[SDImageCache sharedImageCache] cleanDisk];
[[SDImageCache sharedImageCache] clearDisk];