1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// ZJBaseFileModel.m
// RealEstateManagement
//
// Created by Javen on 2017/2/13.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "ZJBaseFileModel.h"
#import "UIImageView+WebCache.h"
@interface ZJBaseFileModel()
{
UIImage *_image;
NSString *_fileUrl;
}
@end
@implementation ZJBaseFileModel
- (instancetype)initWithDictionary:(NSDictionary *)dict {
return [[self class] modelWithDic:dict];
}
- (void)setImageView:(UIImageView *)imageView
{
if (_image != nil) {
imageView.image = _image;
}else{
[self getFileUrlComplelet:^(NSString *fileUrl) {
[imageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:kPlaceHolderImage];
}];
}
}
- (void)getFileUrlComplelet:(void (^)(NSString *fileUrl))fileUrl
{
static NSCache *cache = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
cache = [NSCache new];
});
NSString *url = [cache objectForKey:self.idField];
if (url) {
fileUrl(url);
}else {
// [kHttp getAttachmentWithId:self.idField
// complete:^(NSString *attachmentUrl) {
// _fileUrl = attachmentUrl;
// [cache setObject:attachmentUrl forKey:self.idField];
// fileUrl(attachmentUrl);
// }];
}
}
@end