SetupViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. //
  2. // SetupViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/7.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "SetupViewController.h"
  9. #import "CategoryCell.h"
  10. #import "ZFileManagerHelper.h"
  11. #import "FeedbackViewController.h"//意见反馈
  12. #import "AboutViewController.h"//关于我们
  13. #import "ServiceagreementViewController.h"//服务协议
  14. #import "UserHelper.h"
  15. #import "HuanXinHelper.h"
  16. #import "AgreementViewController.h"
  17. #import "NewModifyPasswordViewController.h"
  18. #import "NewKeFuViewController.h"
  19. #import "SetUpCell.h"
  20. @interface SetupViewController ()<UITableViewDelegate,UITableViewDataSource>{
  21. UITableView *newtableView;
  22. NSMutableArray *dataArray;
  23. NSString *cacheSize;
  24. }
  25. @end
  26. @implementation SetupViewController
  27. - (void)viewWillAppear:(BOOL)animated{
  28. [super viewWillAppear:animated];
  29. cacheSize = [ZFileManagerHelper getCacheSize];
  30. [newtableView reloadData];
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. [self setNavTitle:@"设置"];
  35. [self dataInitialization];
  36. [self loadsView];
  37. // Do any additional setup after loading the view.
  38. }
  39. #pragma mark - 数据初始化
  40. - (void)dataInitialization{
  41. cacheSize = @"0.00K";
  42. dataArray = NewMutableArrayInit;
  43. for (int i=0; i<4; i++) {
  44. NSDictionary *dataDic = [NSDictionary dictionary];
  45. switch (i) {
  46. case 0:
  47. dataDic = @{@"nameKey":@"修改密码",@"imageKey":@"图层 234",@"classKey":@""};
  48. [dataArray addObject:dataDic];
  49. break;
  50. case 1:
  51. dataDic = @{@"nameKey":@"清除缓存",@"imageKey":@"图层 235",@"classKey":@""};
  52. [dataArray addObject:dataDic];
  53. break;
  54. case 2:
  55. dataDic = @{@"nameKey":@"意见反馈",@"imageKey":@"图层 236",@"classKey":@""};
  56. [dataArray addObject:dataDic];
  57. break;
  58. case 3:
  59. dataDic = @{@"nameKey":@"退出登录",@"imageKey":@"图层 239",@"classKey":@""};
  60. [dataArray addObject:dataDic];
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. }
  67. #pragma mark ----加载界面
  68. - (void)loadsView{
  69. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, ViewStartY, SCREEN_WIDTH, SCREEN_HEIGHT-ViewStartY) backgroundColor:NewNavigationColor style:UITableViewStyleGrouped delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  70. newtableView.separatorStyle = YES;
  71. }
  72. #pragma mark-------------------------UITableView------------------------------------
  73. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  74. {
  75. return 1;
  76. }
  77. //返回每段行数
  78. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  79. {
  80. return dataArray.count;
  81. }
  82. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. static NSString *Cell = @"Cell";
  85. SetUpCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  86. if (cell == nil) {
  87. cell = [[SetUpCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  88. }
  89. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  90. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  91. // [cell assignment:dataArray[indexPath.row]];
  92. cell.title.text = dataArray[indexPath.row][@"nameKey"];
  93. [cell.imageview setImage:NewImageNamed(dataArray[indexPath.row][@"imageKey"])];
  94. // if (indexPath.row == 0) {
  95. // UILabel *haha = [[UILabel alloc] init];
  96. // haha.text = cacheSize;
  97. // [haha setSingleLineAutoResizeWithMaxWidth:0];
  98. // [cell.contentView addSubview:haha];
  99. // haha.sd_layout
  100. // .rightSpaceToView(cell.contentView, 10)
  101. // .centerYEqualToView(cell.contentView)
  102. // .heightIs(cell.height);
  103. // }
  104. return cell;
  105. }
  106. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  107. {
  108. return fitScreenHeight(44);
  109. }
  110. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  111. if ([dataArray[indexPath.row][@"nameKey"] isEqualToString:@"清除缓存"]) {
  112. [self Scavengingcaching];
  113. }else if ([dataArray[indexPath.row][@"nameKey"] isEqualToString:@"意见反馈"]) {
  114. NewKeFuViewController *vc = [[NewKeFuViewController alloc] init];
  115. NewPushViewController(vc);
  116. }else if ([dataArray[indexPath.row][@"nameKey"] isEqualToString:@"服务协议"]) {
  117. // AboutViewController *vc = [[AboutViewController alloc] init];
  118. // NewPushViewController(vc);
  119. NewInitWithName(AgreementViewController, vc);
  120. vc.str = @"服务协议";
  121. NewPushViewController(vc);
  122. }else if ([dataArray[indexPath.row][@"nameKey"] isEqualToString:@"关于我们"]){
  123. ServiceagreementViewController *vc = [[ServiceagreementViewController alloc] init];
  124. NewPushViewController(vc);
  125. }else if ([dataArray[indexPath.row][@"nameKey"] isEqualToString:@"修改密码"]){
  126. if ([UserHelper isLogin]) {
  127. NSLog(@"%@",@"已登录");
  128. NewModifyPasswordViewController *vc = [[NewModifyPasswordViewController alloc] init];
  129. NewPushViewController(vc);
  130. }else{
  131. NSLog(@"%@",@"未登录");
  132. NewLoginViewController *vc = [[NewLoginViewController alloc] init];
  133. [vc setLoginSuccess:^(NSString *string) {
  134. NewPopViewController;
  135. }];
  136. NewPushViewController(vc);
  137. }
  138. }else if ([dataArray[indexPath.row][@"nameKey"] isEqualToString:@"退出登录"]){
  139. if ([UserHelper isLogin]) {
  140. NSLog(@"%@",@"已登录");
  141. [self touchExitLogin];//退出登录
  142. }else{
  143. NSLog(@"%@",@"未登录");
  144. [self.view makeToast:@"当前账号未登录!" duration:1.0 position:CSToastPositionCenter];
  145. }
  146. }
  147. }
  148. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  149. return CGFLOAT_MIN;
  150. }
  151. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  152. return CGFLOAT_MIN;
  153. }
  154. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  155. return [[UIView alloc] init];
  156. }
  157. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  158. return [[UIView alloc] init];
  159. }
  160. - (void)submitclick:(UIButton *)btn{
  161. if ([UserHelper isLogin]) {
  162. NSLog(@"%@",@"已登录");
  163. [self touchExitLogin];//退出登录
  164. }else{
  165. NSLog(@"%@",@"未登录");
  166. [self.view makeToast:@"当前账号未登录!" duration:1.0 position:CSToastPositionCenter];
  167. }
  168. }
  169. #pragma mark - 点击退出登录
  170. - (void)touchExitLogin
  171. {
  172. UIAlertController *alertController2 = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否退出登录?" preferredStyle:(UIAlertControllerStyleAlert)];
  173. UIAlertAction *okAction2 = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
  174. //退出登录
  175. [self exitLoginNetworkRequest];
  176. }];
  177. UIAlertAction *cancelAction2 = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) {
  178. //NSLog(@"取消");
  179. }];
  180. [alertController2 addAction:okAction2];
  181. [alertController2 addAction:cancelAction2];
  182. [self presentViewController:alertController2 animated:YES completion:nil];
  183. }
  184. #pragma mark - 退出登录网络请求
  185. - (void)exitLoginNetworkRequest
  186. {
  187. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  188. [MBProgressHUD hideHUDForView:self.view];
  189. //退出云信账号、解绑阿里云推送账号、删除用户单例类以及本地缓存保存的数据
  190. [UserHelper exitLogin];
  191. //退出环信账号
  192. [[HuanXinHelper sharedInstance] exitlogon];
  193. _tuichudenglu(@"退出登录");
  194. NewPopViewController;
  195. // NSMutableDictionary *parameters = NewMutableDictionaryInit;
  196. // [NetworkRequestManager requestGetWithInterfacePrefix:JT_logout parameters:parameters onSuccess:^(id requestData) {
  197. // [MBProgressHUD hideHUDForView:self.view];
  198. // //退出云信账号、解绑阿里云推送账号、删除用户单例类以及本地缓存保存的数据
  199. // [UserHelper exitLogin];
  200. // //退出环信账号
  201. // [[HuanXinHelper sharedInstance] exitlogon];
  202. // NewPopViewController;
  203. // } onFailure:^{
  204. // [MBProgressHUD hideHUDForView:self.view];
  205. //
  206. // }];
  207. }
  208. - (void)Scavengingcaching{
  209. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否清除缓存?" preferredStyle:(UIAlertControllerStyleAlert)];
  210. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
  211. //NSLog(@"确定");
  212. BOOL cleanResult = [ZFileManagerHelper cleanCache];
  213. if (cleanResult) {
  214. [self.view makeToast:@"缓存清除成功!"];
  215. cacheSize = @"0.00K";
  216. [newtableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
  217. }
  218. }];
  219. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) {
  220. //NSLog(@"取消");
  221. }];
  222. [alertController addAction:okAction];
  223. [alertController addAction:cancelAction];
  224. [self presentViewController:alertController animated:YES completion:nil];
  225. }
  226. - (void)didReceiveMemoryWarning {
  227. [super didReceiveMemoryWarning];
  228. // Dispose of any resources that can be recreated.
  229. }
  230. /*
  231. #pragma mark - Navigation
  232. // In a storyboard-based application, you will often want to do a little preparation before navigation
  233. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  234. // Get the new view controller using [segue destinationViewController].
  235. // Pass the selected object to the new view controller.
  236. }
  237. */
  238. @end