FollowerViewController.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // FollowerViewController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 16/6/18.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "FollowerViewController.h"
  9. #import "SSearchVC.h"
  10. #import "FollowerTableViewCell.h"
  11. #import "SenderModel.h"
  12. #import "SHomePageVC.h"
  13. @interface FollowerViewController ()<UITableViewDelegate,UITableViewDataSource>
  14. @property (nonatomic, strong) UITableView *myTableView;
  15. @property (nonatomic, strong) NSMutableArray *dataArray;
  16. @property (nonatomic, assign) int has_next;
  17. @property (nonatomic, assign) int currentPage;
  18. @property (nonatomic, assign) BOOL isfirstLoad;
  19. @end
  20. @implementation FollowerViewController
  21. - (void)viewDidLoad
  22. {
  23. [super viewDidLoad];
  24. }
  25. - (void)viewWillAppear:(BOOL)animated {
  26. [super viewWillAppear:animated];
  27. self.navigationController.navigationBar.hidden = YES;
  28. if (!self.isfirstLoad)
  29. {
  30. [self loadNetDataWithPage:1];
  31. }
  32. self.isfirstLoad = NO;
  33. }
  34. - (void)backLastVC {
  35. [self.navigationController popViewControllerAnimated:YES];
  36. }
  37. - (void)initFWUI
  38. {
  39. [super initFWUI];
  40. self.view.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
  41. UIImageView * navView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationHeight)];
  42. navView.image = [UIImage imageNamed:@"mine_navbg"];
  43. navView.userInteractionEnabled = YES;
  44. [self.view addSubview:navView];
  45. UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  46. [backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  47. backBtn.frame = CGRectMake(10, StatusBarHeight, 44, 44);
  48. [backBtn addTarget:self action:@selector(backLastVC) forControlEvents:UIControlEventTouchUpInside];
  49. [navView addSubview:backBtn];
  50. UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
  51. titleLabel.centerX = SCREEN_WIDTH/2;
  52. titleLabel.centerY = backBtn.centerY;
  53. // titleLabel.text = ASLocalizedString(@"系统设置");
  54. titleLabel.textColor = UIColor.blackColor;
  55. titleLabel.font = [UIFont boldSystemFontOfSize:18];
  56. titleLabel.textAlignment = NSTextAlignmentCenter;
  57. [navView addSubview:titleLabel];
  58. if ([self.type isEqualToString:@"1"])
  59. {
  60. titleLabel.text = ASLocalizedString(@"关注");
  61. }
  62. else if ([self.type isEqualToString:@"2"])
  63. {
  64. titleLabel.text = ASLocalizedString(@"粉丝");
  65. }
  66. else
  67. {
  68. titleLabel.text = ASLocalizedString(@"黑名单");
  69. }
  70. self.dataArray = [[NSMutableArray alloc]init];
  71. self.has_next = 0;
  72. self.currentPage =1;
  73. self.isfirstLoad = YES;
  74. [self creatView];
  75. }
  76. - (void)creatView
  77. {
  78. self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(comeBack) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  79. if ([self.type isEqualToString:@"1"] && [self.user_id isEqualToString:[GlobalVariables sharedInstance].userModel.user_id])
  80. {
  81. self.navigationItem.rightBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(searchController) image:@"ic_me_follow" highImage:@"ic_me_follow"];
  82. }
  83. self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavigationHeight, kScreenW, kScreenH-kStatusBarHeight-kNavigationBarHeight)];
  84. self.myTableView.backgroundColor = UIColor.clearColor;
  85. self.myTableView.dataSource = self;
  86. self.myTableView.delegate = self;
  87. self.myTableView.tag = 1107;
  88. self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  89. [self.myTableView registerNib:[UINib nibWithNibName:@"FollowerTableViewCell" bundle:nil] forCellReuseIdentifier:@"FollowerTableViewCell"];
  90. [self.view addSubview:self.myTableView];
  91. [BGMJRefreshManager refresh:self.myTableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(footerReresh)];
  92. }
  93. - (void)headerReresh
  94. {
  95. [self loadNetDataWithPage:1];
  96. }
  97. - (void)footerReresh
  98. {
  99. if (self.has_next == 1)
  100. {
  101. self.currentPage ++;
  102. [self loadNetDataWithPage:self.currentPage];
  103. }
  104. else
  105. {
  106. [BGMJRefreshManager endRefresh:self.myTableView];
  107. }
  108. }
  109. - (void)loadNetDataWithPage:(int)page
  110. {
  111. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  112. if ([self.type isEqualToString:@"1"])
  113. {
  114. [parmDict setObject:@"user" forKey:@"ctl"];
  115. [parmDict setObject:@"user_follow" forKey:@"act"];
  116. }else if ([self.type isEqualToString:@"2"])
  117. {
  118. [parmDict setObject:@"user" forKey:@"ctl"];
  119. [parmDict setObject:@"user_focus" forKey:@"act"];
  120. }else if ([self.type isEqualToString:@"3"]){
  121. [parmDict setObject:@"settings" forKey:@"ctl"];
  122. [parmDict setObject:@"black_list" forKey:@"act"];
  123. }
  124. if (self.user_id.length > 0)
  125. {
  126. [parmDict setObject:self.user_id forKey:@"to_user_id"];
  127. }
  128. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
  129. FWWeakify(self)
  130. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  131. FWStrongify(self)
  132. if ([responseJson toInt:@"status"] == 1)
  133. {
  134. self.currentPage = [responseJson toInt:@"page"];
  135. if (self.currentPage == 1)
  136. {
  137. [self.dataArray removeAllObjects];
  138. }
  139. self.has_next = [responseJson toInt:@"has_next"];
  140. if ([responseJson toInt:@"status"] == 1)
  141. {
  142. NSArray *listArray ;
  143. //由于字段不同,在设置来源界面做判断
  144. if ([self.type isEqualToString:@"3"])
  145. {
  146. listArray = [responseJson objectForKey:@"user"];
  147. }
  148. else
  149. {
  150. listArray = [responseJson objectForKey:@"list"];
  151. }
  152. for (NSDictionary *dict in listArray)
  153. {
  154. SenderModel *sModel = [SenderModel mj_objectWithKeyValues:dict];
  155. [self.dataArray addObject:sModel];
  156. }
  157. [self.myTableView reloadData];
  158. }
  159. }
  160. [BGMJRefreshManager endRefresh:self.myTableView];
  161. if (!self.dataArray.count)
  162. {
  163. [self showNoContentView];
  164. }
  165. else
  166. {
  167. [self hideNoContentView];
  168. }
  169. } FailureBlock:^(NSError *error) {
  170. FWStrongify(self)
  171. [BGMJRefreshManager endRefresh:self.myTableView];
  172. }];
  173. }
  174. //返回
  175. - (void)comeBack
  176. {
  177. if (self.navigationController.viewControllers.count >1)
  178. {
  179. [self.navigationController popViewControllerAnimated:YES];
  180. }else
  181. {
  182. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  183. }
  184. // [[AppDelegate sharedAppDelegate]popViewController];
  185. }
  186. #pragma mark -UITableViewDelegate&UITableViewDataSource
  187. //返回行数
  188. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  189. {
  190. return 1;
  191. }
  192. //返回段数
  193. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  194. {
  195. return self.dataArray.count;
  196. }
  197. //返回单元格
  198. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  199. {
  200. FollowerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FollowerTableViewCell" forIndexPath:indexPath];
  201. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  202. if (self.dataArray.count > indexPath.section)
  203. {
  204. SenderModel *model = _dataArray[indexPath.section];
  205. [cell creatCellWithModel:model WithRow:(int)indexPath.section];
  206. }
  207. if (self.dataArray.count-1 == indexPath.section)
  208. {
  209. cell.lineView.hidden = YES;
  210. }
  211. if ([self.type isEqualToString:@"3"])
  212. {
  213. cell.joinBtn.userInteractionEnabled = YES;
  214. [cell.joinBtn setTitle:ASLocalizedString(@"移除黑名单") forState:UIControlStateNormal];
  215. cell.cellType = self.type.intValue;
  216. WeakSelf
  217. cell.reloadCellData = ^(NSInteger index) {
  218. [weakSelf.dataArray removeObjectAtIndex:index];
  219. [weakSelf.myTableView reloadData];
  220. };
  221. // cell.rightImgView.userInteractionEnabled = NO;
  222. // cell.rightImgView.image = [UIImage imageNamed:@"me_black"];
  223. } else if (self.type.intValue == 2) {
  224. [cell.joinBtn setTitle:ASLocalizedString(@"回关") forState:UIControlStateNormal];
  225. }
  226. return cell;
  227. }
  228. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  229. {
  230. SenderModel *sModel = _dataArray[indexPath.section];
  231. SHomePageVC *homeVC = [[SHomePageVC alloc]init];
  232. homeVC.user_id = sModel.user_id;
  233. homeVC.type = 0;
  234. // homeVC.user_nickname = sModel.nick_name;
  235. // homeVC.user_headimg = sModel.head_image;
  236. [self.navigationController pushViewController:homeVC animated:YES];
  237. }
  238. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  239. {
  240. return 80*kAppRowHScale;
  241. }
  242. //下一个页面
  243. - (void)searchController
  244. {
  245. SSearchVC *searchVC = [[SSearchVC alloc]init];
  246. searchVC.searchType = @"0";
  247. [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
  248. }
  249. @end