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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// ICRTaskResultViewController.m
// XFFruit
//
// Created by Xummer on 4/12/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "ICRTaskResultViewController.h"
#import "ICRTaskResultContentView.h"
#import "ICRTask.h"
@interface ICRTaskResultViewController ()
@property (strong, nonatomic) IBTUIScrollView *m_scrollView;
@property (strong, nonatomic) ICRTaskResultContentView *m_contentView;
@property (strong, nonatomic) ICRTask *m_task;
@end
@implementation ICRTaskResultViewController
#pragma mark - Life Cycle
- (instancetype)initWithTaskData:(ICRTask *)task {
self = [super init];
if (!self) {
return nil;
}
self.m_task = task;
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = [IBTCommon localizableString:@"Task"];
[self initContentView];
[self registerContentViewForKVO];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[self unregisterContentViewFromKVO];
}
#pragma mark - Private Method
- (void)initContentView {
self.m_scrollView = [[IBTUIScrollView alloc] initWithFrame:self.view.bounds];
[_m_scrollView autoresizingWithStrechFullSize];
[self.view addSubview:_m_scrollView];
self.m_contentView = [[ICRTaskResultContentView alloc] init];
_m_contentView.frame = _m_scrollView.bounds;
[_m_contentView updateWithTask:_m_task];
[_m_scrollView addSubview:_m_contentView];
_m_scrollView.contentSize = _m_contentView.size;
}
#pragma mark - Update Data
- (void)doHttpGetAttachment {
__weak typeof(self)weakSelf = self;
void(^succ)(id) = ^(id data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
[strongSelf.m_contentView updateWithTask:_m_task];
};
void(^fail)(id) = ^(id data) {
[IBTLoadingView showTips:data];
};
ICRHTTPController *httpCtrl = [ICRHTTPController sharedController];
[httpCtrl doGetAttachmentListWithType:kAttachmentTask
objID:_m_task.uuid
success:succ
failure:fail];
}
#pragma mark - KVO
- (void)registerContentViewForKVO {
for (NSString *keyPath in [self observableKeypaths]) {
[_m_contentView addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:NULL];
}
}
- (void)unregisterContentViewFromKVO {
for (NSString *keyPath in [self observableKeypaths]) {
[_m_contentView removeObserver:self forKeyPath:keyPath];
}
}
- (NSArray *)observableKeypaths {
return @[ @"frame" ];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
_m_scrollView.contentSize = _m_contentView.size;
}
@end