| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // SettingTableViewController.m
- // NIMDemo
- //
- // Created by Fenix Wang on 2017/6/15.
- // Copyright © 2017年 Netease. All rights reserved.
- //
- #import "SettingTableViewController.h"
- #import "NIMAvatarImageView.h"
- #import "User.h"
- #import "NIMSDK/NIMSDK.h"
- #import "UIView+NTES.h"
- #import "UIImageView+WebCache.h"
- #import "SettingTopTableViewCell.h"
- #import "AppDelegate.h"
- #import "SettingOptionTableViewCell.h"
- #import "NTESUserInfoSettingViewController.h"
- #import "HttpRequest.h"
- #import "UIView+Toast.h"
- @interface SettingTableViewController ()
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic, strong) NSMutableArray *socialList;
- @end
- @implementation SettingTableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self fillData];
- self.tableView.contentInset = UIEdgeInsetsMake(-69, 0, 0, 0);
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
- UINavigationItem *navItem = self.parentViewController.navigationItem;
-
- [navItem setTitle:@""];
-
- UIButton *emptyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [emptyBtn setTitle:@"" forState:UIControlStateNormal];
- [emptyBtn sizeToFit];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:emptyBtn];
-
- [navItem setLeftBarButtonItems:@[leftItem]];
-
-
- UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [addBtn setImage:[UIImage imageNamed:@"设置图标"] forState:UIControlStateNormal];
- [addBtn addTarget:self action:@selector(onTouchSetting:) forControlEvents:UIControlEventTouchUpInside];
- [addBtn setFrame:CGRectMake(0, 0, 30, 30)];
- UIBarButtonItem *addItem = [[UIBarButtonItem alloc] initWithCustomView:addBtn];
-
- [navItem setRightBarButtonItems:@[addItem]];
- }
- - (void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate transparentNavBar:self.parentViewController];
-
- [self fillData];
- [self.tableView reloadData];
-
- [self fetchSocial];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate orangeNavBar:self.parentViewController];
- }
- - (void)fillData{
- _dataArr = [[NSMutableArray alloc] init];
-
- float topHeight = 340;
- float photoHeight = [User sharedInfo].userInfo.photeArr.count >= 5 ? self.view.width / 5 * 2 : self.view.width / 5;
- float socialHeight = 130;
- topHeight += photoHeight + socialHeight;
-
- [_dataArr addObject:@{@"cellId":@"top",
- @"height":[@(topHeight) stringValue]}];
-
- [_dataArr addObject:@{@"cellId":@"option",
- @"type":@"near",
- @"height":@"44"}];
-
- [_dataArr addObject:@{@"cellId":@"option",
- @"type":@"trade",
- @"height":@"44"}];
-
- [_dataArr addObject:@{@"cellId":@"option",
- @"type":@"setting",
- @"height":@"44"}];
- }
- - (void)fetchSocial{
- __weak typeof(self) wself = self;
- [[HttpRequest shared] getSocialDataList:nil targetId:[NIMSDK sharedSDK].loginManager.currentAccount success:^(NSMutableArray * _Nullable dataList) {
- wself.socialList = dataList;
- [wself.tableView reloadData];
- } failure:^{
- [self.view makeToast:@"获取动态失败"];
- }];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if(_dataArr)
- return _dataArr.count;
- return 0;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- NSDictionary *dataObj = [_dataArr objectAtIndex:indexPath.row];
- NSString *cellId = [dataObj objectForKey:@"cellId"];
-
- UITableViewCell *baseCell = nil;
-
- if([cellId isEqualToString:@"top"])
- {
- SettingTopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
- if(!cell)
- {
- cell = [[SettingTopTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
- [cell initSize:self.view.width cellHeight:[[dataObj objectForKey:@"height"] floatValue]];
- }
- [cell fillPhotos];
- [cell fillSocial:self.socialList];
- baseCell = cell;
- }
- else if([cellId isEqualToString:@"option"])
- {
- SettingOptionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
- if(!cell)
- {
- cell = [[SettingOptionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
- [cell initWidth:self.view.width];
- }
- [cell setData:dataObj];
- baseCell = cell;
- }
-
- return baseCell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- NSDictionary *dataObj = [_dataArr objectAtIndex:indexPath.row];
- float height = [[dataObj objectForKey:@"height"] floatValue];
-
- return height;
- }
- - (void)onTouchSetting:(id)sender{
- // NTESUserInfoSettingViewController *vc = [[NTESUserInfoSettingViewController alloc] initWithNibName:nil bundle:nil];
- // [self.navigationController pushViewController:vc animated:YES];
-
- [User showUserInfo:[NIMSDK sharedSDK].loginManager.currentAccount viewController:self];
- }
- @end
|