ReleaseTopicVC.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //
  2. // ReleaseTopicVC.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/11/28.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "ReleaseTopicVC.h"
  9. #import "ReleaseTopicCell.h"
  10. @interface ReleaseTopicVC ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource>
  11. @property (nonatomic,strong) UITableView *tableView;
  12. @property (nonatomic,strong) NSMutableArray *dataArray;
  13. @property ( nonatomic,assign) int page;
  14. @property(nonatomic,strong) UIButton *closeBtn;
  15. @property(nonatomic, strong) UITextField *myTextFiled;
  16. @end
  17. @implementation ReleaseTopicVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.navigationController.navigationBar.hidden = YES;
  21. [self initNavView];
  22. self.page = 1;
  23. self.dataArray = [NSMutableArray array];
  24. [self configureData];
  25. [self initUI];
  26. // Do any additional setup after loading the view.
  27. }
  28. - (void)initNavView{
  29. self.closeBtn = ({
  30. UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
  31. [btn setTitle:ASLocalizedString(@"取消")forState:UIControlStateNormal];
  32. [btn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  33. btn.titleLabel.font = [UIFont systemFontOfSize:16];
  34. [btn addTarget:self action:@selector(closeButtonClick) forControlEvents:UIControlEventTouchUpInside];
  35. btn;
  36. });
  37. [self.view addSubview:self.closeBtn];
  38. UIImageView * imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"搜索框"]];
  39. // imageView.contentMode = UIViewContentModeScaleToFill
  40. [self.view addSubview:imageView];
  41. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.mas_equalTo(12 + MG_TOP_MARGIN);
  43. make.left.mas_equalTo(10);
  44. make.height.mas_equalTo(32);
  45. make.right.equalTo(self.closeBtn.mas_left).offset(-25);
  46. }];
  47. imageView.userInteractionEnabled = YES;
  48. [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.right.mas_equalTo(-10);
  50. make.centerY.mas_equalTo(imageView.mas_centerY);
  51. }];
  52. UIImageView * imageViewTopic = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"话题"]];
  53. [imageView addSubview:imageViewTopic];
  54. [imageViewTopic mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.centerY.equalTo(imageView);
  56. make.left.mas_equalTo(20);
  57. make.size.mas_equalTo(13);
  58. // make.right.equalTo(self.closeBtn.mas_left).offset(25);
  59. }];
  60. [imageView addSubview:self.myTextFiled];
  61. self.myTextFiled.textAlignment = NSTextAlignmentLeft;
  62. [self.myTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.centerY.equalTo(imageView);
  64. make.left.mas_equalTo(36);
  65. make.right.mas_equalTo(-10);
  66. // make.right.equalTo(self.closeBtn.mas_left).offset(25);
  67. }];
  68. }
  69. - (void)closeButtonClick{
  70. [self.navigationController popViewControllerAnimated:YES];
  71. }
  72. - (void)initUI{
  73. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, (kNavigationBarHeight+kStatusBarHeight), kScreenW, kScreenH - (kNavigationBarHeight+kStatusBarHeight)) style:UITableViewStylePlain];
  74. // if (isIPhoneX()) {
  75. // self.tableView.height = kScreenH - 49 - 64 - 20;
  76. // }
  77. NSLog(@"%f",kTabBarHeight);
  78. NSLog(@"%f",kNavigationBarHeight);
  79. self.tableView.delegate = self;
  80. self.tableView.dataSource = self;
  81. // self.tableView.backgroundColor = RGBCOLOR(244, 244, 244);
  82. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  83. [self.view addSubview:self.tableView];
  84. self.view.backgroundColor = kWhiteColor;
  85. [self.tableView registerClass:[ReleaseTopicCell class] forCellReuseIdentifier:NSStringFromClass([ReleaseTopicCell class])];
  86. // [self.tableView registerClass:[CellForWorkGroupRepost class] forCellReuseIdentifier:NSStringFromClass([CellForWorkGroupRepost class])];
  87. // [BGMJRefreshManager refresh:self.tableView target:self headerRereshAction:@selector(refreshHeader) footerRereshAction:@selector(refreshFooter)];
  88. [self requestData];
  89. }
  90. #pragma mark 下拉刷新
  91. - (void)refreshHeader
  92. {
  93. self.page = 1;
  94. [self loadDataWithPage:1];
  95. }
  96. #pragma mark 上拉加载
  97. - (void)refreshFooter
  98. {
  99. self.page ++;
  100. [self loadDataWithPage:self.page];
  101. }
  102. - (void)loadDataWithPage:(int)page
  103. {
  104. [BGMJRefreshManager endRefresh:self.tableView];
  105. }
  106. - (void)requestData{
  107. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  108. [parmDict setObject:@"dynamic" forKey:@"ctl"];
  109. [parmDict setObject:@"dynamic_theme" forKey:@"act"];
  110. FWWeakify(self)
  111. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  112. NSArray * array = responseJson[@"data"];
  113. for (id obj in array)
  114. {
  115. MGDynamicTopicModel *model =[MGDynamicTopicModel mj_objectWithKeyValues:obj];
  116. [self.dataArray addObject:model];
  117. }
  118. [self.tableView reloadData];
  119. } FailureBlock:^(NSError *error) {
  120. }];
  121. }
  122. - (void)configureData{
  123. // while (self.dataArray.count < 10) {
  124. // DTTopicModel * model = [[DTTopicModel alloc]init];
  125. // model.title = [NSString stringWithFormat:ASLocalizedString(@"话题%d"),arc4random_uniform(30)];
  126. // [self.dataArray addObject:model];
  127. // }
  128. }
  129. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  130. return 1;
  131. }
  132. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  133. return self.dataArray.count;
  134. }
  135. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  136. return 55;
  137. }
  138. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  139. ReleaseTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ReleaseTopicCell class])];
  140. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  141. cell.topic = self.dataArray[indexPath.row];
  142. return cell;
  143. }
  144. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  145. [self.myTextFiled resignFirstResponder];
  146. [self.navigationController popViewControllerAnimated:NO];
  147. //将TopicModel传递过去
  148. !self.releaseTopicBlock?:self.releaseTopicBlock(self.dataArray[indexPath.row]);
  149. }
  150. - (void)textFieldDidChange:(UITextField*) sender
  151. {
  152. // [self loadNetDataWithPage:_currentPage andTextFiledStr:sender.text];
  153. }
  154. - (UITextField *)myTextFiled
  155. {
  156. if (!_myTextFiled)
  157. {
  158. _myTextFiled = [[UITextField alloc]initWithFrame:CGRectMake(35*kScaleWidth, (44-25*kScaleWidth)/2, kScreenW -110*kScaleWidth, 25*kScaleWidth)];
  159. _myTextFiled.backgroundColor = kClearColor;
  160. // _myTextFiled.layer.cornerRadius = 25*kScaleWidth/2;
  161. _myTextFiled.textAlignment = NSTextAlignmentCenter;
  162. _myTextFiled.font = [UIFont systemFontOfSize:14];
  163. _myTextFiled.delegate = self;
  164. [_myTextFiled addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  165. _myTextFiled.clearsOnBeginEditing = NO;
  166. // _myTextFiled.clearsContextBeforeDrawing = YES;
  167. _myTextFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
  168. _myTextFiled.leftViewMode = UITextFieldViewModeAlways;//设置左边距显示的时机,这个表示一直显示
  169. _myTextFiled.placeholder = ASLocalizedString(@"话题搜索");
  170. }
  171. return _myTextFiled;
  172. }
  173. @end