YBCitySelVC.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // YBCitySelVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2020/10/17.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "YBCitySelVC.h"
  9. #import "YBCitySelCell.h"
  10. @interface YBCitySelVC ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. int _paging;
  13. int _allNums;
  14. }
  15. @property(nonatomic,strong)UITableView *tableView;
  16. @property(nonatomic,strong)NSMutableArray *dataArray;
  17. @property(nonatomic,strong)NSMutableArray *indexArray;
  18. @property(nonatomic,strong)UIView *tableHeader;
  19. @property(nonatomic,strong)UILabel *tableHTL;
  20. @property(nonatomic,strong)UILabel *tableCityL;
  21. @end
  22. @implementation YBCitySelVC
  23. - (void)viewWillAppear:(BOOL)animated{
  24. [super viewWillAppear:animated];
  25. // [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  26. [self pullData];
  27. }
  28. - (UIStatusBarStyle)preferredStatusBarStyle {
  29. if (@available(iOS 13.0,*)) {
  30. return UIStatusBarStyleDarkContent;
  31. }
  32. return UIStatusBarStyleDefault;
  33. }
  34. - (void)viewWillDisappear:(BOOL)animated{
  35. // [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  36. }
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. self.view.backgroundColor = UIColor.whiteColor;
  40. self.subNavi.backgroundColor = UIColor.whiteColor;
  41. self.titleL.text = YZMsg(@"切换城市");
  42. self.titleL.textColor= UIColor.blackColor;
  43. self.leftBtn.imageEdgeInsets = UIEdgeInsetsMake(13, 13, 13, 13);
  44. [self.leftBtn setImage:[UIImage imageNamed:@"gray_close"] forState:0];
  45. _paging = 1;
  46. _allNums = 0;
  47. self.dataArray = [NSMutableArray array];
  48. self.indexArray = [NSMutableArray array];
  49. [self.view addSubview:self.tableView];
  50. self.tableView.tableHeaderView = self.tableHeader;
  51. self.tableView.tableHeaderView.frame = CGRectMake(0, 0, _window_width, 90);
  52. }
  53. #pragma mark -
  54. -(void)pullData {
  55. [YBNetworking postWithUrl:@"Video.getCitys" Dic:@{} Suc:^(int code, id info, NSString *msg) {
  56. [_tableView.mj_header endRefreshing];
  57. [_tableView.mj_footer endRefreshing];
  58. if (code == 0) {
  59. NSArray *infoA = [NSArray arrayWithArray:info];
  60. if (_paging == 1) {
  61. [_dataArray removeAllObjects];
  62. [_indexArray removeAllObjects];
  63. _allNums = 0;
  64. }
  65. if (infoA.count <= 0) {
  66. [_tableView.mj_footer endRefreshingWithNoMoreData];
  67. }else {
  68. [_dataArray addObjectsFromArray:infoA];
  69. for (int i = 0; i < infoA.count; i++) {
  70. NSDictionary *subDic = infoA[i];
  71. [_indexArray addObject:minstr([subDic valueForKey:@"title"])];
  72. NSArray *listA = [NSArray arrayWithArray:[subDic valueForKey:@"lists"]];
  73. _allNums += listA.count;
  74. }
  75. }
  76. if (_allNums <= 0) {
  77. [PublicView showTextNoData:_tableView text1:@"" text2:YZMsg(@"暂无数据") centerY:0.8];
  78. }else {
  79. [PublicView hiddenTextNoData:_tableView];
  80. }
  81. [_tableView reloadData];
  82. }else {
  83. [MBProgressHUD showPop:msg];
  84. }
  85. } Fail:^(id fail) {
  86. [_tableView.mj_header endRefreshing];
  87. [_tableView.mj_footer endRefreshing];
  88. }];
  89. }
  90. #pragma mark - UITableViewDelegate、UITableViewDataSource
  91. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  92. return 30;
  93. }
  94. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  95. UIView *headerVie = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 30)];
  96. headerVie.backgroundColor = RGB_COLOR(@"#F0F0F0", 1);
  97. NSDictionary *subDic = _dataArray[section];
  98. UILabel *titleL = [[UILabel alloc]init];
  99. titleL.font = SYS_Font(16);
  100. titleL.textColor = RGB_COLOR(@"#323232", 1);
  101. titleL.text = minstr([subDic valueForKey:@"title"]);
  102. [headerVie addSubview:titleL];
  103. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.equalTo(headerVie.mas_left).offset(15);
  105. make.centerY.equalTo(headerVie);
  106. }];
  107. return headerVie;
  108. }
  109. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  110. return 0;
  111. }
  112. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  113. return nil;
  114. }
  115. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  116. return 50;
  117. }
  118. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  119. return _dataArray.count;
  120. }
  121. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  122. NSDictionary *subDic = _dataArray[section];
  123. NSArray *listA = @[];
  124. if ([[subDic valueForKey:@"lists"] isKindOfClass:[NSArray class]]) {
  125. listA = [NSArray arrayWithArray:[subDic valueForKey:@"lists"]];
  126. }
  127. return listA.count;
  128. }
  129. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  130. YBCitySelCell *cell = [YBCitySelCell cellWithTab:tableView index:indexPath];
  131. NSDictionary *subDic = _dataArray[indexPath.section];
  132. NSArray *listA = @[];
  133. if ([[subDic valueForKey:@"lists"] isKindOfClass:[NSArray class]]) {
  134. listA = [NSArray arrayWithArray:[subDic valueForKey:@"lists"]];
  135. }
  136. cell.cityNameL.text = listA[indexPath.row];
  137. return cell;
  138. }
  139. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  140. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  141. NSDictionary *subDic = _dataArray[indexPath.section];
  142. NSArray *listA = @[];
  143. if ([[subDic valueForKey:@"lists"] isKindOfClass:[NSArray class]]) {
  144. listA = [NSArray arrayWithArray:[subDic valueForKey:@"lists"]];
  145. }
  146. NSString *cityName = listA[indexPath.row];
  147. if (self.citySelEvent) {
  148. self.citySelEvent(cityName);
  149. }
  150. [self clickNaviLeftBtn];
  151. }
  152. -(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{
  153. return _indexArray;
  154. }
  155. #pragma mark - set/get
  156. -(UITableView *)tableView {
  157. if (!_tableView) {
  158. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight, _window_width, _window_height - 64-statusbarHeight)style:UITableViewStyleGrouped];
  159. _tableView.delegate = self;
  160. _tableView.dataSource = self;
  161. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  162. _tableView.backgroundColor = UIColor.whiteColor;
  163. _tableView.sectionIndexColor = UIColor.blackColor;
  164. }
  165. return _tableView;
  166. }
  167. - (UIView *)tableHeader {
  168. if (!_tableHeader) {
  169. _tableHeader = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 80)];
  170. _tableHeader.backgroundColor =UIColor.whiteColor;
  171. UIImageView *locIV = [[UIImageView alloc]init];
  172. locIV.image = [UIImage imageNamed:@"城市-定位"];
  173. [_tableHeader addSubview:locIV];
  174. _tableHTL = [[UILabel alloc]init];
  175. _tableHTL.font = SYS_Font(14);
  176. _tableHTL.text = YZMsg(@"自动定位");
  177. _tableHTL.textColor = UIColor.blackColor;
  178. [_tableHeader addSubview:_tableHTL];
  179. _tableCityL = [[UILabel alloc]init];
  180. NSString *curStr = [PublicObj checkNull:[cityDefault getLocationCity]]?@"":[cityDefault getLocationCity];
  181. if ([curStr hasSuffix:@"市"]) {
  182. curStr = [curStr substringToIndex:curStr.length-1];
  183. }
  184. _tableCityL.text = curStr;
  185. _tableCityL.font = SYS_Font(16);
  186. _tableCityL.textColor = UIColor.blackColor;
  187. [_tableHeader addSubview:_tableCityL];
  188. [_tableHTL mas_makeConstraints:^(MASConstraintMaker *make) {
  189. make.height.mas_equalTo(30);
  190. make.top.equalTo(_tableHeader);
  191. make.left.equalTo(locIV.mas_right).offset(3);
  192. }];
  193. [locIV mas_makeConstraints:^(MASConstraintMaker *make) {
  194. make.width.height.mas_equalTo(12);
  195. make.left.equalTo(_tableHeader.mas_left).offset(15);
  196. make.centerY.equalTo(_tableHTL);
  197. }];
  198. [_tableCityL mas_makeConstraints:^(MASConstraintMaker *make) {
  199. make.left.equalTo(locIV);
  200. make.right.lessThanOrEqualTo(_tableHeader.mas_right).offset(-15);
  201. make.bottom.equalTo(_tableHeader);
  202. make.height.mas_equalTo(50);
  203. }];
  204. UIButton *shadowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  205. [shadowBtn addTarget:self action:@selector(clickShadowBtn) forControlEvents:UIControlEventTouchUpInside];
  206. [_tableHeader addSubview:shadowBtn];
  207. [shadowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.width.bottom.centerX.equalTo(_tableHeader);
  209. make.height.equalTo(_tableCityL);
  210. }];
  211. }
  212. return _tableHeader;
  213. }
  214. -(void)clickShadowBtn {
  215. NSString *curStr = [PublicObj checkNull:[cityDefault getLocationCity]]?@"":[cityDefault getLocationCity];
  216. if ([curStr hasSuffix:@"市"]) {
  217. curStr = [curStr substringToIndex:curStr.length-1];
  218. }
  219. if (self.citySelEvent) {
  220. self.citySelEvent(curStr);
  221. }
  222. [self clickNaviLeftBtn];
  223. }
  224. @end