8
8
9
9
#import " SettingViewController.h"
10
10
#import " TitleDisclosureCell.h"
11
+ #import " TitleValueMoreCell.h"
11
12
#import " Login.h"
12
13
#import " AppDelegate.h"
13
14
#import " SettingAccountViewController.h"
14
15
#import " AboutViewController.h"
15
16
#import " EditTopicViewController.h"
17
+ #import " CodingShareView.h"
18
+ #import " WebViewController.h"
16
19
17
- @interface SettingViewController ()
20
+ @interface SettingViewController ()<UITableViewDataSource, UITableViewDelegate>
18
21
@property (strong , nonatomic ) UITableView *myTableView;
19
22
@end
20
23
@@ -34,6 +37,7 @@ - (void)viewDidLoad
34
37
tableView.delegate = self;
35
38
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
36
39
[tableView registerClass: [TitleDisclosureCell class ] forCellReuseIdentifier: kCellIdentifier_TitleDisclosure ];
40
+ [tableView registerClass: [TitleValueMoreCell class ] forCellReuseIdentifier: kCellIdentifier_TitleValueMore ];
37
41
[self .view addSubview: tableView];
38
42
[tableView mas_makeConstraints: ^(MASConstraintMaker *make) {
39
43
make.edges .equalTo (self.view );
@@ -43,54 +47,43 @@ - (void)viewDidLoad
43
47
_myTableView.tableFooterView = [self tableFooterView ];
44
48
}
45
49
46
- - (void )didReceiveMemoryWarning
47
- {
48
- [super didReceiveMemoryWarning ];
49
- // Dispose of any resources that can be recreated.
50
+ - (UIView*)tableFooterView {
51
+ UIView *footerV = [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , kScreen_Width , 90 )];
52
+ UIButton *loginBtn = [UIButton buttonWithStyle: StrapWarningStyle andTitle: @" 退出" andFrame: CGRectMake (10 , 0 , kScreen_Width -10 *2 , 45 ) target: self action: @selector (loginOutBtnClicked: )];
53
+ [loginBtn setCenter: footerV.center];
54
+ [footerV addSubview: loginBtn];
55
+ return footerV;
50
56
}
51
57
58
+ - (void )dealloc {
59
+ _myTableView.delegate = nil ;
60
+ _myTableView.dataSource = nil ;
61
+ }
52
62
#pragma mark TableM
53
63
- (NSInteger )numberOfSectionsInTableView : (UITableView *)tableView {
54
- return 3 ;
64
+ return 4 ;
55
65
}
56
66
- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section {
57
- NSInteger row = 0 ;
58
- switch (section) {
59
- case 0 :
60
- row = 1 ;
61
- break ;
62
- case 1 :
63
- row = 2 ;
64
- break ;
65
- default :
66
- row = 1 ;
67
- break ;
68
- }
67
+ NSInteger row = (section == 1 ? 3 :
68
+ section == 3 ? 2 :
69
+ 1 );
69
70
return row;
70
71
}
71
72
72
73
- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
73
- TitleDisclosureCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_TitleDisclosure forIndexPath: indexPath];
74
- switch (indexPath.section ) {
75
- case 0 :
76
- [cell setTitleStr: @" 账号设置" ];
77
- break ;
78
- case 1 :
79
- switch (indexPath.row ) {
80
- case 0 :
81
- [cell setTitleStr: @" 意见反馈" ];
82
- break ;
83
- case 1 :
84
- [cell setTitleStr: @" 去评分" ];
85
- break ;
86
- default :
87
- [cell setTitleStr: @" 分享给好友" ];
88
- break ;
89
- }
90
- break ;
91
- default :
92
- [cell setTitleStr: @" 关于Coding" ];
93
- break ;
74
+ UITableViewCell *cell;
75
+ if (indexPath.section == 2 ) {
76
+ cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_TitleValueMore forIndexPath: indexPath];
77
+ [(TitleValueMoreCell *)cell setTitleStr: @" 清除缓存" valueStr: [self p_diskCacheSizeStr ]];
78
+ }else {
79
+ cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_TitleDisclosure forIndexPath: indexPath];
80
+
81
+ NSString *titleStr = (indexPath.section == 0 ? @" 账号设置" :
82
+ indexPath.section == 1 ? (indexPath.row == 0 ? @" 意见反馈" :
83
+ indexPath.row == 1 ? @" 去评分" :
84
+ @" 推荐 Coding" ):
85
+ indexPath.row == 0 ? @" 帮助中心" : @" 关于Coding" );
86
+ [(TitleDisclosureCell *)cell setTitleStr: titleStr];
94
87
}
95
88
[tableView addLineforPlainCell: cell forRowAtIndexPath: indexPath withLeftSpace: kPaddingLeftWidth ];
96
89
return cell;
@@ -109,65 +102,68 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege
109
102
return 0.5 ;
110
103
}
111
104
112
- #pragma mark -
113
-
114
105
- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath {
115
106
[tableView deselectRowAtIndexPath: indexPath animated: YES ];
116
- switch (indexPath.section ) {
117
- case 0 :{// 账号设置
118
- SettingAccountViewController *vc = [[SettingAccountViewController alloc ] init ];
107
+
108
+ if (indexPath.section == 0 ) {// 账号设置
109
+ SettingAccountViewController *vc = [[SettingAccountViewController alloc ] init ];
110
+ [self .navigationController pushViewController: vc animated: YES ];
111
+ }else if (indexPath.section == 1 ){
112
+ if (indexPath.row == 0 ) {// 意见反馈
113
+ EditTopicViewController *vc = [[EditTopicViewController alloc ] init ];
114
+ vc.curProTopic = [ProjectTopic feedbackTopic ];
115
+ vc.type = TopicEditTypeFeedBack;
116
+ vc.topicChangedBlock = nil ;
119
117
[self .navigationController pushViewController: vc animated: YES ];
118
+ }else if (indexPath.row == 1 ){// 评分
119
+ [[UIApplication sharedApplication ] openURL: [NSURL URLWithString: kAppReviewURL ]];
120
+ }else {// 推荐 Coding
121
+ [CodingShareView showShareViewWithObj: nil ];
120
122
}
121
- break ;
122
- case 1 :
123
- switch (indexPath.row ) {
124
- case 0 :{// 意见反馈
125
- EditTopicViewController *vc = [[EditTopicViewController alloc ] init ];
126
- vc.curProTopic = [ProjectTopic feedbackTopic ];
127
- vc.type = TopicEditTypeFeedBack;
128
- vc.topicChangedBlock = nil ;
129
- [self .navigationController pushViewController: vc animated: YES ];
130
- }
131
- break ;
132
- case 1 :{// 评分
133
- [[UIApplication sharedApplication ] openURL: [NSURL URLWithString: kAppReviewURL ]];
134
- }
135
- break ;
136
- default :
137
- break ;
123
+ }else if (indexPath.section == 2 ){// 清除缓存
124
+ __weak typeof (self) weakSelf = self;
125
+ [[UIActionSheet bk_actionSheetCustomWithTitle: @" 缓存数据有助于再次浏览或离线查看,你确定要清除缓存吗?" buttonTitles: nil destructiveTitle: @" 确定清除" cancelTitle: @" 取消" andDidDismissBlock: ^(UIActionSheet *sheet, NSInteger index ) {
126
+ if (index == 0 ) {
127
+ [weakSelf clearDiskCache ];
138
128
}
139
- break ;
140
- default :{// 关于
129
+ }] showInView: self .view];
130
+ }else {
131
+ if (indexPath.row == 0 ) {
132
+ WebViewController *webVc = [WebViewController webVCWithUrlStr: @" /help/doc/mobile/index.html " ];
133
+ [self .navigationController pushViewController: webVc animated: YES ];
134
+ }else {// 关于
141
135
AboutViewController *vc = [[AboutViewController alloc ] init ];
142
136
[self .navigationController pushViewController: vc animated: YES ];
143
137
}
144
- break ;
138
+
145
139
}
146
140
}
147
141
148
- - (UIView*)tableFooterView {
149
- UIView *footerV = [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , kScreen_Width , 90 )];
150
- UIButton *loginBtn = [UIButton buttonWithStyle: StrapWarningStyle andTitle: @" 退出" andFrame: CGRectMake (10 , 0 , kScreen_Width -10 *2 , 45 ) target: self action: @selector (loginOutBtnClicked: )];
151
- [loginBtn setCenter: footerV.center];
152
- [footerV addSubview: loginBtn];
153
- return footerV;
154
- }
142
+ #pragma mark - Action
155
143
156
144
- (void )loginOutBtnClicked : (id )sender {
157
- UIActionSheet *actionSheet = [[UIActionSheet alloc ] initWithTitle: @" 确定要退出当前账号" delegate: self cancelButtonTitle: @" 取消" destructiveButtonTitle: @" 确定退出" otherButtonTitles: nil ];
158
- [actionSheet showInView: self .view];
145
+ __weak typeof (self) weakSelf = self;
146
+ [[UIActionSheet bk_actionSheetCustomWithTitle: @" 确定要退出当前账号吗?" buttonTitles: nil destructiveTitle: @" 确定退出" cancelTitle: @" 取消" andDidDismissBlock: ^(UIActionSheet *sheet, NSInteger index ) {
147
+ if (index == 0 ) {
148
+ [weakSelf loginOutToLoginVC ];
149
+ }
150
+ }] showInView: self .view];
159
151
}
160
152
161
- #pragma mark UIActionSheetDelegate M
162
- - (void )actionSheet : (UIActionSheet *)actionSheet didDismissWithButtonIndex : (NSInteger )buttonIndex {
163
- if (buttonIndex == 0 ) {
164
- [self loginOutToLoginVC ];
165
- }
153
+ - (void )clearDiskCache {
154
+ [NSObject showHUDQueryStr: @" 正在清除缓存..." ];
155
+ [NSObject deleteResponseCache ];
156
+ [[SDImageCache sharedImageCache ] clearDiskOnCompletion: ^{
157
+ [NSObject hideHUDQuery ];
158
+ [NSObject showHudTipStr: @" 清除缓存成功" ];
159
+ [self .myTableView reloadData ];
160
+ }];
166
161
}
167
162
168
- - (void ) dealloc
169
- {
170
- _myTableView. delegate = nil ;
171
- _myTableView. dataSource = nil ;
163
+ - (NSString *) p_diskCacheSizeStr {
164
+ NSUInteger size = [[SDImageCache sharedImageCache ] getSize ];
165
+ size += [ NSObject getResponseCacheSize ] ;
166
+ return [ NSString stringWithFormat: @" %.2f M " , size/ 1024.0 / 1024.0 ] ;
172
167
}
168
+
173
169
@end
0 commit comments