您的位置:首页 > 其它

第三方加载图片

2015-09-01 19:34 260 查看
​#import "TableViewCell.h"
#import "ImageModal.h"
// 下载图片(MRC)
#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

// 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];
}
// 刷新cell(解析完数据)
[self.mainTableView reloadData];
}];
}
清除缓存
// 清除缓存
[[SDImageCache sharedImageCache] cleanDisk];
[[SDImageCache sharedImageCache] clearDisk];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: