| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- //
- // FollowerViewController.m
- // BuguLive
- //
- // Created by fanwe2014 on 16/6/18.
- // Copyright © 2016年 xfg. All rights reserved.
- //
- #import "FollowerViewController.h"
- #import "SSearchVC.h"
- #import "FollowerTableViewCell.h"
- #import "SenderModel.h"
- #import "SHomePageVC.h"
- @interface FollowerViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView *myTableView;
- @property (nonatomic, strong) NSMutableArray *dataArray;
- @property (nonatomic, assign) int has_next;
- @property (nonatomic, assign) int currentPage;
- @property (nonatomic, assign) BOOL isfirstLoad;
- @end
- @implementation FollowerViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
-
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- self.navigationController.navigationBar.hidden = YES;
-
- if (!self.isfirstLoad)
- {
- [self loadNetDataWithPage:1];
- }
- self.isfirstLoad = NO;
- }
- - (void)backLastVC {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)initFWUI
- {
- [super initFWUI];
-
- self.view.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
-
- UIImageView * navView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationHeight)];
- navView.image = [UIImage imageNamed:@"mine_navbg"];
- navView.userInteractionEnabled = YES;
- [self.view addSubview:navView];
-
- UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
- backBtn.frame = CGRectMake(10, StatusBarHeight, 44, 44);
- [backBtn addTarget:self action:@selector(backLastVC) forControlEvents:UIControlEventTouchUpInside];
- [navView addSubview:backBtn];
-
- UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
- titleLabel.centerX = SCREEN_WIDTH/2;
- titleLabel.centerY = backBtn.centerY;
- // titleLabel.text = ASLocalizedString(@"系统设置");
- titleLabel.textColor = UIColor.blackColor;
- titleLabel.font = [UIFont boldSystemFontOfSize:18];
- titleLabel.textAlignment = NSTextAlignmentCenter;
- [navView addSubview:titleLabel];
-
- if ([self.type isEqualToString:@"1"])
- {
- titleLabel.text = ASLocalizedString(@"关注");
- }
- else if ([self.type isEqualToString:@"2"])
- {
- titleLabel.text = ASLocalizedString(@"粉丝");
- }
- else
- {
- titleLabel.text = ASLocalizedString(@"黑名单");
- }
- self.dataArray = [[NSMutableArray alloc]init];
- self.has_next = 0;
- self.currentPage =1;
- self.isfirstLoad = YES;
- [self creatView];
- }
- - (void)creatView
- {
- self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(comeBack) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
-
- if ([self.type isEqualToString:@"1"] && [self.user_id isEqualToString:[GlobalVariables sharedInstance].userModel.user_id])
- {
- self.navigationItem.rightBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(searchController) image:@"ic_me_follow" highImage:@"ic_me_follow"];
- }
-
- self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavigationHeight, kScreenW, kScreenH-kStatusBarHeight-kNavigationBarHeight)];
- self.myTableView.backgroundColor = UIColor.clearColor;
- self.myTableView.dataSource = self;
- self.myTableView.delegate = self;
- self.myTableView.tag = 1107;
- self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.myTableView registerNib:[UINib nibWithNibName:@"FollowerTableViewCell" bundle:nil] forCellReuseIdentifier:@"FollowerTableViewCell"];
- [self.view addSubview:self.myTableView];
-
- [BGMJRefreshManager refresh:self.myTableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(footerReresh)];
- }
- - (void)headerReresh
- {
- [self loadNetDataWithPage:1];
- }
- - (void)footerReresh
- {
- if (self.has_next == 1)
- {
- self.currentPage ++;
- [self loadNetDataWithPage:self.currentPage];
- }
- else
- {
- [BGMJRefreshManager endRefresh:self.myTableView];
- }
- }
- - (void)loadNetDataWithPage:(int)page
- {
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
- if ([self.type isEqualToString:@"1"])
- {
- [parmDict setObject:@"user" forKey:@"ctl"];
- [parmDict setObject:@"user_follow" forKey:@"act"];
- }else if ([self.type isEqualToString:@"2"])
- {
- [parmDict setObject:@"user" forKey:@"ctl"];
- [parmDict setObject:@"user_focus" forKey:@"act"];
- }else if ([self.type isEqualToString:@"3"]){
- [parmDict setObject:@"settings" forKey:@"ctl"];
- [parmDict setObject:@"black_list" forKey:@"act"];
- }
- if (self.user_id.length > 0)
- {
- [parmDict setObject:self.user_id forKey:@"to_user_id"];
- }
- [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
-
- FWWeakify(self)
- [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
-
- FWStrongify(self)
- if ([responseJson toInt:@"status"] == 1)
- {
- self.currentPage = [responseJson toInt:@"page"];
- if (self.currentPage == 1)
- {
- [self.dataArray removeAllObjects];
- }
- self.has_next = [responseJson toInt:@"has_next"];
-
- if ([responseJson toInt:@"status"] == 1)
- {
- NSArray *listArray ;
- //由于字段不同,在设置来源界面做判断
- if ([self.type isEqualToString:@"3"])
- {
- listArray = [responseJson objectForKey:@"user"];
- }
- else
- {
- listArray = [responseJson objectForKey:@"list"];
- }
- for (NSDictionary *dict in listArray)
- {
- SenderModel *sModel = [SenderModel mj_objectWithKeyValues:dict];
- [self.dataArray addObject:sModel];
- }
- [self.myTableView reloadData];
- }
- }
- [BGMJRefreshManager endRefresh:self.myTableView];
-
- if (!self.dataArray.count)
- {
- [self showNoContentView];
- }
- else
- {
- [self hideNoContentView];
- }
-
- } FailureBlock:^(NSError *error) {
-
- FWStrongify(self)
- [BGMJRefreshManager endRefresh:self.myTableView];
-
- }];
- }
- //返回
- - (void)comeBack
- {
- if (self.navigationController.viewControllers.count >1)
- {
- [self.navigationController popViewControllerAnimated:YES];
- }else
- {
- [self.navigationController dismissViewControllerAnimated:YES completion:nil];
- }
- // [[AppDelegate sharedAppDelegate]popViewController];
- }
- #pragma mark -UITableViewDelegate&UITableViewDataSource
- //返回行数
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 1;
- }
- //返回段数
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return self.dataArray.count;
- }
- //返回单元格
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- FollowerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FollowerTableViewCell" forIndexPath:indexPath];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- if (self.dataArray.count > indexPath.section)
- {
- SenderModel *model = _dataArray[indexPath.section];
- [cell creatCellWithModel:model WithRow:(int)indexPath.section];
- }
- if (self.dataArray.count-1 == indexPath.section)
- {
- cell.lineView.hidden = YES;
- }
- if ([self.type isEqualToString:@"3"])
- {
- cell.joinBtn.userInteractionEnabled = YES;
- [cell.joinBtn setTitle:ASLocalizedString(@"移除黑名单") forState:UIControlStateNormal];
- cell.cellType = self.type.intValue;
- WeakSelf
- cell.reloadCellData = ^(NSInteger index) {
- [weakSelf.dataArray removeObjectAtIndex:index];
- [weakSelf.myTableView reloadData];
- };
- // cell.rightImgView.userInteractionEnabled = NO;
- // cell.rightImgView.image = [UIImage imageNamed:@"me_black"];
- } else if (self.type.intValue == 2) {
- [cell.joinBtn setTitle:ASLocalizedString(@"回关") forState:UIControlStateNormal];
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- SenderModel *sModel = _dataArray[indexPath.section];
- SHomePageVC *homeVC = [[SHomePageVC alloc]init];
- homeVC.user_id = sModel.user_id;
- homeVC.type = 0;
- // homeVC.user_nickname = sModel.nick_name;
- // homeVC.user_headimg = sModel.head_image;
- [self.navigationController pushViewController:homeVC animated:YES];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 80*kAppRowHScale;
- }
- //下一个页面
- - (void)searchController
- {
- SSearchVC *searchVC = [[SSearchVC alloc]init];
- searchVC.searchType = @"0";
- [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
- }
- @end
|