videoTopicVC.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // videoTopicVC.m
  3. // YBVideo
  4. //
  5. // Created by IOS1 on 2019/7/2.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "videoTopicVC.h"
  9. #import "HXSearchBar.h"
  10. #import "videoTopicCell.h"
  11. @interface videoTopicVC ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>{
  12. HXSearchBar *searchBars;
  13. NSMutableArray *allArray;
  14. int p;
  15. }
  16. @property (nonatomic,strong) UITableView *topicTableView;
  17. @end
  18. @implementation videoTopicVC
  19. //添加搜索条
  20. - (void)addSearchBar {
  21. UIView *bg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, statusbarHeight+70)];
  22. bg.backgroundColor = CellRow_Cor;
  23. [self.view addSubview:bg];
  24. //加上 搜索栏
  25. searchBars = [[HXSearchBar alloc] initWithFrame:CGRectMake(10,10+statusbarHeight, self.view.frame.size.width -20,60)];
  26. searchBars.backgroundColor = CellRow_Cor;
  27. searchBars.delegate = self;
  28. //输入框提示
  29. searchBars.placeholder = YZMsg(@"搜索话题标签");
  30. //光标颜色
  31. searchBars.cursorColor = [UIColor whiteColor];
  32. //TextField
  33. searchBars.searchBarTextField.layer.cornerRadius = 18;
  34. searchBars.searchBarTextField.layer.masksToBounds = YES;
  35. //searchBars.searchBarTextField.layer.borderColor = [UIColor grayColor].CGColor;
  36. //searchBars.searchBarTextField.layer.borderWidth = 1.0;
  37. searchBars.searchBarTextField.backgroundColor = RGB_COLOR(@"#201F37", 1);
  38. searchBars.searchBarTextField.textColor = [UIColor whiteColor];
  39. searchBars.searchBarTextField.font = [UIFont systemFontOfSize:14];
  40. //清除按钮图标
  41. //searchBar.clearButtonImage = [UIImage imageNamed:@"demand_delete"];
  42. UIButton *clearBtn = [searchBars.searchBarTextField valueForKey:@"_clearButton"];
  43. [clearBtn addTarget:self action:@selector(clickClearBtn) forControlEvents:UIControlEventTouchUpInside];
  44. //去掉取消按钮灰色背景
  45. searchBars.hideSearchBarBackgroundImage = YES;
  46. [searchBars becomeFirstResponder];
  47. [bg addSubview:searchBars];
  48. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, bg.bottom, _window_width-15, 50)];
  49. label.text = YZMsg(@"所有标签");
  50. label.textColor = RGB_COLOR(@"#959595", 1);
  51. label.font = [UIFont systemFontOfSize:12];
  52. [self.view addSubview:label];
  53. }
  54. - (void)clickClearBtn{
  55. [self requestData];
  56. }
  57. #pragma mark - 搜索代理
  58. - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
  59. HXSearchBar *sear = (HXSearchBar *)searchBar;
  60. sear.cancleButton.backgroundColor = [UIColor clearColor];
  61. [sear.cancleButton setTitle:YZMsg(@"取消") forState:UIControlStateNormal];
  62. [sear.cancleButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  63. sear.cancleButton.titleLabel.font = [UIFont systemFontOfSize:16];
  64. }
  65. //文字改变
  66. -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
  67. if (searchText.length>0) {
  68. [self searchData];
  69. }else{
  70. [self requestData];
  71. }
  72. }
  73. //取消按钮点击的回调
  74. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
  75. searchBar.showsCancelButton = NO;
  76. searchBar.text = nil;
  77. [self.view endEditing:YES];
  78. [self.navigationController popViewControllerAnimated:YES];
  79. [self dismissViewControllerAnimated:YES completion:nil];
  80. }
  81. - (UITableView *)topicTableView{
  82. if (!_topicTableView) {
  83. _topicTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, statusbarHeight+120, _window_width, _window_height-120-statusbarHeight)];
  84. _topicTableView.backgroundColor = Normal_Color;
  85. _topicTableView.delegate = self;
  86. _topicTableView.dataSource = self;
  87. _topicTableView.separatorStyle = 0;
  88. [self.view addSubview:_topicTableView];
  89. // _topicTableView.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
  90. // p = 1;
  91. // [self requestData];
  92. // }];
  93. // _topicTableView.mj_footer = [MJRefreshBackFooter footerWithRefreshingBlock:^{
  94. // p++;
  95. // [self requestData];
  96. // }];
  97. }
  98. return _topicTableView;
  99. }
  100. - (void)viewDidLoad {
  101. [super viewDidLoad];
  102. self.naviView.hidden = YES;
  103. self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;
  104. self.view.backgroundColor = Normal_Color;
  105. allArray = [NSMutableArray array];
  106. p = 1;
  107. [self addSearchBar];
  108. [self.view addSubview:self.topicTableView];
  109. [self requestData];
  110. }
  111. - (void)requestData{
  112. [YBNetworking postWithUrl:@"Label.getList" Dic:nil Suc:^(int code, id info, NSString *msg) {
  113. // [_topicTableView.mj_header endRefreshing];
  114. // [_topicTableView.mj_footer endRefreshing];
  115. if (code == 0) {
  116. [allArray removeAllObjects];
  117. NSArray *infoA = [NSArray arrayWithArray:info];
  118. [allArray addObjectsFromArray:infoA];
  119. [_topicTableView reloadData];
  120. }else {
  121. [MBProgressHUD showPop:msg];
  122. }
  123. } Fail:^(id fail) {
  124. // [_topicTableView.mj_header endRefreshing];
  125. // [_topicTableView.mj_footer endRefreshing];
  126. }];
  127. }
  128. - (void)searchData{
  129. [YBNetworking postWithUrl:@"Label.SearchLabel" Dic:@{@"key":searchBars.text} Suc:^(int code, id info, NSString *msg) {
  130. // [_topicTableView.mj_header endRefreshing];
  131. // [_topicTableView.mj_footer endRefreshing];
  132. if (code == 0) {
  133. [allArray removeAllObjects];
  134. NSArray *infoA = [NSArray arrayWithArray:info];
  135. [allArray addObjectsFromArray:infoA];
  136. [_topicTableView reloadData];
  137. }else {
  138. [MBProgressHUD showPop:msg];
  139. }
  140. } Fail:^(id fail) {
  141. // [_topicTableView.mj_header endRefreshing];
  142. // [_topicTableView.mj_footer endRefreshing];
  143. }];
  144. }
  145. -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
  146. [self.view endEditing:YES];
  147. }
  148. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  149. return allArray.count;
  150. }
  151. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  152. videoTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:@"videoTopicCELL"];
  153. if (!cell) {
  154. cell = [[[NSBundle mainBundle] loadNibNamed:@"videoTopicCell" owner:nil options:nil] lastObject];
  155. }
  156. cell.topicTitleL.text = minstr([allArray[indexPath.row] valueForKey:@"name"]);
  157. cell.backgroundColor = CellRow_Cor;
  158. cell.contentView.backgroundColor = CellRow_Cor;
  159. return cell;
  160. }
  161. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  162. return 50;
  163. }
  164. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  165. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  166. if (self.block) {
  167. self.block(allArray[indexPath.row]);
  168. [self.view endEditing:YES];
  169. [self dismissViewControllerAnimated:YES completion:nil];
  170. }
  171. }
  172. /*
  173. #pragma mark - Navigation
  174. // In a storyboard-based application, you will often want to do a little preparation before navigation
  175. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  176. // Get the new view controller using [segue destinationViewController].
  177. // Pass the selected object to the new view controller.
  178. }
  179. */
  180. @end