| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- //
- // BSetViewController.m
- // HappyJob
- //
- // Created by 张晓光 on 2019/7/4.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "BSetViewController.h"
- #import "BMyListCell.h"
- #import "BIdentitySwitchViewController.h"//身份切换
- #import "HJConfirmPanelViewController.h"//退出登录
- #import "HJLoginViewController.h"
- @interface BSetViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) UIButton *exitBtn;
- @end
- @implementation BSetViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.title = @"设置";
- [self hj_setupWhiteColorNavBar];
- [self autoLayOutViews];
- }
- #pragma mark - UITableView
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- return 2 ;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *listCell = @"listCell";
- BMyListCell *cell = [tableView dequeueReusableCellWithIdentifier:listCell];
- if (cell == nil)
- {
- cell = [[BMyListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:listCell];
- }
- if (indexPath.row == 0)
- {
- cell.titleLabel.text = @"清除缓存";
- cell.leftImageV.image = [UIImage imageNamed:@"b_set_clear"];
- cell.rightLabel.text = [NSString stringWithFormat:@"%.2fMB",[self folderSize]];
- }
- if (indexPath.row == 1)
- {
- cell.titleLabel.text = @"切换身份";
- cell.leftImageV.image = [UIImage imageNamed:@"b_set_ID"];
- cell.rightLabel.text = @"";
- }
- return cell;
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (indexPath.row == 0)
- {
- [self removeCache];
- }
- if (indexPath.row == 1)
- {
- BIdentitySwitchViewController *vc = [[BIdentitySwitchViewController alloc]init];
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- /*
- *缓存大小
- */
- - (CGFloat)folderSize {
-
- CGFloat folderSize = 0.0;
- //获取路径
- NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)firstObject];
- //获取所有文件的数组
- NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath];
-
- for(NSString *path in files)
- {
- NSString*filePath = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",path]];
- //累加
- folderSize += [[NSFileManager defaultManager]attributesOfItemAtPath:filePath error:nil].fileSize;
- }
- //转换为M为单位
- CGFloat sizeM = folderSize /1024.0/1024.0;
- return sizeM;
- }
- /*
- *清除缓存
- */
- - (void)removeCache {
-
- NSString*cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)objectAtIndex:0];
- //返回路径中的文件数组
- NSArray*files = [[NSFileManager defaultManager]subpathsAtPath:cachePath];
-
- for(NSString *p in files)
- {
- NSError*error;
- NSString*path = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",p]];
-
- if([[NSFileManager defaultManager]fileExistsAtPath:path])
- {
- BOOL isRemove = [[NSFileManager defaultManager]removeItemAtPath:path error:&error];
- if(isRemove)
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- //主线程刷新
- [self.tableView reloadData];
- [self.view fb_showSuccessWithStatus:@"清除成功"];
- });
- }
- }
- }
- }
- /* 退出登录*/
- - (void)exitButtonClick {
-
- HJConfirmPanelViewController *vc = [[HJConfirmPanelViewController alloc] init];
- vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
- vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
- self.navigationController.definesPresentationContext = NO;
- vc.titleLabel.text = @"是否退出登录状态?";
- vc.titleIcon.image = nil;
- [vc.cancelButton setTitle:@"返回" forState:UIControlStateNormal];
- [vc.confirmButton setTitle:@"退出登录" forState:UIControlStateNormal];
- [vc.confirmButton addTarget:self
- action:@selector(logoutConfirmButtonClicked:)
- forControlEvents:UIControlEventTouchUpInside];
- [self presentViewController:vc animated:YES completion:nil];
-
- }
- - (void)logoutConfirmButtonClicked:(UIButton *)sender {
-
- [self dismissViewControllerAnimated:NO completion:^{
- // 清空所有本地用户信息
- [[HJAppUserType sharedInstance] loginoutType];
- [[HJAppUserType sharedInstance] saveUserType];
- [HJUserInfoModel clear];
- AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appdelegate switchTabBar];
- }];
- }
- #pragma mark - setter&getter
- - (void)autoLayOutViews {
-
- __weak typeof(self) weakSelf = self;
- [self.view addSubview:self.tableView];
- [self.view addSubview:self.exitBtn];
- self.view.backgroundColor = COLOR_GRAYFA;
- self.tableView.bounces = NO;
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.left.right.offset(0);
- make.top.equalTo(weakSelf.view).offset(NAVIGATION_H);
- make.height.mas_equalTo(200);
- }];
- [self.exitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.centerX.equalTo(weakSelf.view);
- make.bottom.equalTo(weakSelf.view).offset(-64);
- make.size.mas_offset(CGSizeMake(280, 50));
-
- }];
-
- self.exitBtn.layer.cornerRadius = 50/2;
- self.exitBtn.layer.masksToBounds = YES;
-
- }
- - (UITableView *)tableView {
-
- if (_tableView == nil)
- {
- _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = NO;
- _tableView.rowHeight = UITableViewAutomaticDimension;
- _tableView.backgroundColor = COLOR_GRAYFA;
- _tableView.estimatedRowHeight = 10.0;
- }
- return _tableView;
- }
- - (UIButton *)exitBtn {
-
- if (_exitBtn == nil)
- {
- _exitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_exitBtn setTitle:@"退出登录" forState:UIControlStateNormal];
- _exitBtn.titleLabel.font = [UIFont systemFontOfSize:17];
- _exitBtn.backgroundColor = COLOR_DEFAULT;
- [_exitBtn addTarget:self action:@selector(exitButtonClick) forControlEvents:UIControlEventTouchUpInside];
- [_exitBtn az_setGradientBackgroundWithColors:@[[UIColor colorFromHexString:@"219BEE"],[UIColor colorFromHexString:@"2BB0F5"]] locations:@[@(0.0),@(1.0f)] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
- }
- return _exitBtn;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|