SettingTableViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // SettingTableViewController.m
  3. // NIMDemo
  4. //
  5. // Created by Fenix Wang on 2017/6/15.
  6. // Copyright © 2017年 Netease. All rights reserved.
  7. //
  8. #import "SettingTableViewController.h"
  9. #import "NIMAvatarImageView.h"
  10. #import "User.h"
  11. #import "NIMSDK/NIMSDK.h"
  12. #import "UIView+NTES.h"
  13. #import "UIImageView+WebCache.h"
  14. #import "SettingTopTableViewCell.h"
  15. #import "AppDelegate.h"
  16. #import "SettingOptionTableViewCell.h"
  17. #import "NTESUserInfoSettingViewController.h"
  18. #import "HttpRequest.h"
  19. #import "UIView+Toast.h"
  20. @interface SettingTableViewController ()
  21. @property (nonatomic, strong) NSMutableArray *dataArr;
  22. @property (nonatomic, strong) NSMutableArray *socialList;
  23. @end
  24. @implementation SettingTableViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self fillData];
  28. self.tableView.contentInset = UIEdgeInsetsMake(-69, 0, 0, 0);
  29. }
  30. - (void)didReceiveMemoryWarning {
  31. [super didReceiveMemoryWarning];
  32. }
  33. - (void)viewWillAppear:(BOOL)animated{
  34. [super viewWillAppear:animated];
  35. UINavigationItem *navItem = self.parentViewController.navigationItem;
  36. [navItem setTitle:@""];
  37. UIButton *emptyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  38. [emptyBtn setTitle:@"" forState:UIControlStateNormal];
  39. [emptyBtn sizeToFit];
  40. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:emptyBtn];
  41. [navItem setLeftBarButtonItems:@[leftItem]];
  42. UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  43. [addBtn setImage:[UIImage imageNamed:@"设置图标"] forState:UIControlStateNormal];
  44. [addBtn addTarget:self action:@selector(onTouchSetting:) forControlEvents:UIControlEventTouchUpInside];
  45. [addBtn setFrame:CGRectMake(0, 0, 30, 30)];
  46. UIBarButtonItem *addItem = [[UIBarButtonItem alloc] initWithCustomView:addBtn];
  47. [navItem setRightBarButtonItems:@[addItem]];
  48. }
  49. - (void)viewDidAppear:(BOOL)animated{
  50. [super viewDidAppear:animated];
  51. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  52. [appDelegate transparentNavBar:self.parentViewController];
  53. [self fillData];
  54. [self.tableView reloadData];
  55. [self fetchSocial];
  56. }
  57. - (void)viewWillDisappear:(BOOL)animated{
  58. [super viewWillDisappear:animated];
  59. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  60. [appDelegate orangeNavBar:self.parentViewController];
  61. }
  62. - (void)fillData{
  63. _dataArr = [[NSMutableArray alloc] init];
  64. float topHeight = 340;
  65. float photoHeight = [User sharedInfo].userInfo.photeArr.count >= 5 ? self.view.width / 5 * 2 : self.view.width / 5;
  66. float socialHeight = 130;
  67. topHeight += photoHeight + socialHeight;
  68. [_dataArr addObject:@{@"cellId":@"top",
  69. @"height":[@(topHeight) stringValue]}];
  70. [_dataArr addObject:@{@"cellId":@"option",
  71. @"type":@"near",
  72. @"height":@"44"}];
  73. [_dataArr addObject:@{@"cellId":@"option",
  74. @"type":@"trade",
  75. @"height":@"44"}];
  76. [_dataArr addObject:@{@"cellId":@"option",
  77. @"type":@"setting",
  78. @"height":@"44"}];
  79. }
  80. - (void)fetchSocial{
  81. __weak typeof(self) wself = self;
  82. [[HttpRequest shared] getSocialDataList:nil targetId:[NIMSDK sharedSDK].loginManager.currentAccount success:^(NSMutableArray * _Nullable dataList) {
  83. wself.socialList = dataList;
  84. [wself.tableView reloadData];
  85. } failure:^{
  86. [self.view makeToast:@"获取动态失败"];
  87. }];
  88. }
  89. #pragma mark - Table view data source
  90. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  91. return 1;
  92. }
  93. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  94. if(_dataArr)
  95. return _dataArr.count;
  96. return 0;
  97. }
  98. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  99. NSDictionary *dataObj = [_dataArr objectAtIndex:indexPath.row];
  100. NSString *cellId = [dataObj objectForKey:@"cellId"];
  101. UITableViewCell *baseCell = nil;
  102. if([cellId isEqualToString:@"top"])
  103. {
  104. SettingTopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  105. if(!cell)
  106. {
  107. cell = [[SettingTopTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  108. [cell initSize:self.view.width cellHeight:[[dataObj objectForKey:@"height"] floatValue]];
  109. }
  110. [cell fillPhotos];
  111. [cell fillSocial:self.socialList];
  112. baseCell = cell;
  113. }
  114. else if([cellId isEqualToString:@"option"])
  115. {
  116. SettingOptionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  117. if(!cell)
  118. {
  119. cell = [[SettingOptionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  120. [cell initWidth:self.view.width];
  121. }
  122. [cell setData:dataObj];
  123. baseCell = cell;
  124. }
  125. return baseCell;
  126. }
  127. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  128. NSDictionary *dataObj = [_dataArr objectAtIndex:indexPath.row];
  129. float height = [[dataObj objectForKey:@"height"] floatValue];
  130. return height;
  131. }
  132. - (void)onTouchSetting:(id)sender{
  133. // NTESUserInfoSettingViewController *vc = [[NTESUserInfoSettingViewController alloc] initWithNibName:nil bundle:nil];
  134. // [self.navigationController pushViewController:vc animated:YES];
  135. [User showUserInfo:[NIMSDK sharedSDK].loginManager.currentAccount viewController:self];
  136. }
  137. @end