88
99#import " SettingViewController.h"
1010#import " TitleDisclosureCell.h"
11+ #import " TitleValueMoreCell.h"
1112#import " Login.h"
1213#import " AppDelegate.h"
1314#import " SettingAccountViewController.h"
1415#import " AboutViewController.h"
1516#import " EditTopicViewController.h"
17+ #import " CodingShareView.h"
18+ #import " WebViewController.h"
1619
17- @interface SettingViewController ()
20+ @interface SettingViewController ()<UITableViewDataSource, UITableViewDelegate>
1821@property (strong , nonatomic ) UITableView *myTableView;
1922@end
2023
@@ -34,6 +37,7 @@ - (void)viewDidLoad
3437 tableView.delegate = self;
3538 tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
3639 [tableView registerClass: [TitleDisclosureCell class ] forCellReuseIdentifier: kCellIdentifier_TitleDisclosure ];
40+ [tableView registerClass: [TitleValueMoreCell class ] forCellReuseIdentifier: kCellIdentifier_TitleValueMore ];
3741 [self .view addSubview: tableView];
3842 [tableView mas_makeConstraints: ^(MASConstraintMaker *make) {
3943 make.edges .equalTo (self.view );
@@ -43,54 +47,43 @@ - (void)viewDidLoad
4347 _myTableView.tableFooterView = [self tableFooterView ];
4448}
4549
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;
5056}
5157
58+ - (void )dealloc {
59+ _myTableView.delegate = nil ;
60+ _myTableView.dataSource = nil ;
61+ }
5262#pragma mark TableM
5363- (NSInteger )numberOfSectionsInTableView : (UITableView *)tableView {
54- return 3 ;
64+ return 4 ;
5565}
5666- (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 );
6970 return row;
7071}
7172
7273- (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];
9487 }
9588 [tableView addLineforPlainCell: cell forRowAtIndexPath: indexPath withLeftSpace: kPaddingLeftWidth ];
9689 return cell;
@@ -109,65 +102,68 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege
109102 return 0.5 ;
110103}
111104
112- #pragma mark -
113-
114105- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath {
115106 [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 ;
119117 [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 ];
120122 }
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 ];
138128 }
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 {// 关于
141135 AboutViewController *vc = [[AboutViewController alloc ] init ];
142136 [self .navigationController pushViewController: vc animated: YES ];
143137 }
144- break ;
138+
145139 }
146140}
147141
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
155143
156144- (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];
159151}
160152
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+ }];
166161}
167162
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 ] ;
172167}
168+
173169@end
0 commit comments