第三方加载图片

来源:互联网 发布:中国黑科技知乎 编辑:程序博客网 时间:2024/04/29 10:16
#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];
0 0
原创粉丝点击