WFCMeTableViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // MeTableViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/11/4.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCMeTableViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <SDWebImage/SDWebImage.h>
  11. #import <WFChatUIKit/WFChatUIKit.h>
  12. #import "WFCSettingTableViewController.h"
  13. #import "WFCSecurityTableViewController.h"
  14. #import "WFCMeTableViewHeaderViewCell.h"
  15. #import "UIColor+YH.h"
  16. @interface WFCMeTableViewController () <UITableViewDataSource, UITableViewDelegate>
  17. @property (nonatomic, strong)UITableView *tableView;
  18. @property (nonatomic, strong)UIImageView *portraitView;
  19. @property (nonatomic, strong)NSArray *itemDataSource;
  20. @end
  21. @implementation WFCMeTableViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.view.backgroundColor = [UIColor whiteColor];
  25. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
  26. self.tableView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  27. self.tableView.delegate = self;
  28. self.tableView.dataSource = self;
  29. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  30. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  31. self.tableView.tableHeaderView = nil;
  32. [self.tableView reloadData];
  33. self.tableView.estimatedRowHeight = 0;
  34. self.tableView.estimatedSectionHeaderHeight = 0;
  35. self.tableView.estimatedSectionFooterHeight = 0;
  36. if ([self.tableView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
  37. if (@available(iOS 11.0, *)) {
  38. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  39. } else {
  40. // Fallback on earlier versions
  41. }
  42. }
  43. [self.view addSubview:self.tableView];
  44. __weak typeof(self)ws = self;
  45. [[NSNotificationCenter defaultCenter] addObserverForName:kUserInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  46. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:note.object]) {
  47. [ws.tableView reloadData];
  48. }
  49. }];
  50. self.itemDataSource = @[
  51. @{@"title":LocalizedString(@"MessageNotification"),
  52. @"image":@"notification_setting"},
  53. @{@"title":LocalizedString(@"AccountSafety"),
  54. @"image":@"safe_setting"},
  55. @{@"title":LocalizedString(@"Settings"),
  56. @"image":@"MoreSetting"}
  57. ];
  58. }
  59. - (void)viewWillAppear:(BOOL)animated {
  60. [super viewWillAppear:animated];
  61. [self.tableView reloadData];
  62. self.navigationController.navigationBar.hidden = YES;
  63. }
  64. - (void)didReceiveMemoryWarning {
  65. [super didReceiveMemoryWarning];
  66. // Dispose of any resources that can be recreated.
  67. }
  68. #pragma mark - Table view data source
  69. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  70. return 4;
  71. }
  72. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  73. return 1;
  74. }
  75. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  76. if (section == 0) {
  77. return 0.01;
  78. } else {
  79. return 9;
  80. }
  81. }
  82. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  83. if (section == 0) {
  84. return nil;
  85. } else {
  86. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 9)];
  87. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  88. return view;
  89. }
  90. }
  91. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  92. if(indexPath.section == 0) {
  93. WFCMeTableViewHeaderViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"profileCell"];
  94. if (cell == nil) {
  95. cell = [[WFCMeTableViewHeaderViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"profileCell"];
  96. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  97. }
  98. WFCCUserInfo *me = [[WFCCIMService sharedWFCIMService] getUserInfo:[WFCCNetworkService sharedInstance].userId refresh:YES];
  99. cell.userInfo = me;
  100. cell.backgroundColor = [WFCUConfigManager globalManager].naviBackgroudColor;
  101. return cell;
  102. } else {
  103. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"styleDefault"];
  104. if (cell == nil) {
  105. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"styleDefault"];
  106. }
  107. cell.accessoryType = UITableViewCellAccessoryNone;
  108. cell.accessoryView = nil;
  109. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  110. cell.textLabel.text = self.itemDataSource[indexPath.section - 1][@"title"];
  111. cell.imageView.image = [UIImage imageNamed:self.itemDataSource[indexPath.section - 1][@"image"]];
  112. return cell;
  113. }
  114. return nil;
  115. }
  116. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  117. if (indexPath.section == 0) {
  118. return 154;
  119. } else {
  120. return 50;
  121. }
  122. }
  123. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  124. if (indexPath.section == 0) {
  125. WFCUMyProfileTableViewController *vc = [[WFCUMyProfileTableViewController alloc] init];
  126. vc.hidesBottomBarWhenPushed = YES;
  127. [self.navigationController pushViewController:vc animated:YES];
  128. } else if (indexPath.section == 1) {
  129. WFCUMessageNotificationViewController *mnvc = [[WFCUMessageNotificationViewController alloc] init];
  130. mnvc.hidesBottomBarWhenPushed = YES;
  131. [self.navigationController pushViewController:mnvc animated:YES];
  132. } else if(indexPath.section == 2) {
  133. WFCSecurityTableViewController * stvc = [[WFCSecurityTableViewController alloc] init];
  134. stvc.hidesBottomBarWhenPushed = YES;
  135. [self.navigationController pushViewController:stvc animated:YES];
  136. } else {
  137. WFCSettingTableViewController *vc = [[WFCSettingTableViewController alloc] init];
  138. vc.hidesBottomBarWhenPushed = YES;
  139. [self.navigationController pushViewController:vc animated:YES];
  140. }
  141. }
  142. - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
  143. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  144. }
  145. - (void)viewWillDisappear:(BOOL)animated {
  146. [super viewWillDisappear:animated];
  147. self.navigationController.navigationBar.hidden = NO;
  148. }
  149. - (void)dealloc {
  150. [[NSNotificationCenter defaultCenter] removeObserver:self];
  151. }
  152. @end