BogoCountryChoiceViewController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // BogoCountryChoiceViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/9/25.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoCountryChoiceViewController.h"
  9. #import "BogoChoiceAreaCell.h"
  10. @interface BogoCountryChoiceViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
  11. @property(nonatomic, strong) UITableView *tableView;
  12. @property(nonatomic, strong) UITextField *searchField;
  13. @property(nonatomic, strong) NSMutableArray *dataArr;
  14. @end
  15. @implementation BogoCountryChoiceViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. [self setUpView];
  20. [self.view addSubview:self.searchField];
  21. [self.view addSubview:self.tableView];
  22. self.dataArr = [NSMutableArray array];
  23. self.view.backgroundColor = kWhiteColor;
  24. }
  25. -(void)setUpView{
  26. UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  27. [cancleBtn setTitle:ASLocalizedString(@"取消") forState:UIControlStateNormal];
  28. [cancleBtn setTitleColor:[UIColor colorWithHexString:@"#777777"] forState:UIControlStateNormal];
  29. cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  30. [cancleBtn addTarget:self action:@selector(clickCancleBtn:) forControlEvents:UIControlEventTouchUpInside];
  31. UILabel *titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW / 2, kRealValue(30))];
  32. titleL.text =ASLocalizedString( @"选择国家/地区");
  33. titleL.textColor = [UIColor colorWithHexString:@"#333333"];
  34. titleL.font = [UIFont systemFontOfSize:18];
  35. titleL.textAlignment = NSTextAlignmentCenter;
  36. titleL.centerX = kScreenW / 2;
  37. cancleBtn.frame = CGRectMake(kRealValue(10), kStatusBarHeight, 44, 44);
  38. titleL.centerY = cancleBtn.centerY;
  39. [self.view addSubview:cancleBtn];
  40. [self.view addSubview:titleL];
  41. self.dataArr = [NSMutableArray array];
  42. [self requestModelWithPageIndex:1];
  43. }
  44. -(void)clickCancleBtn:(UIButton *)sender{
  45. [self.navigationController popViewControllerAnimated:YES];
  46. }
  47. -(void)requestModelWithPageIndex:(NSInteger)pageIndex{
  48. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  49. [parmDict setObject:@"login" forKey:@"ctl"];
  50. [parmDict setObject:@"mobile_code" forKey:@"act"];
  51. [parmDict setObject:[NSString stringWithFormat:@"%ld",pageIndex] forKey:@"p"];
  52. [parmDict setObject:self.searchField.text forKey:@"keyword"];
  53. FWWeakify(self)
  54. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  55. FWStrongify(self)
  56. if (pageIndex == 1) {
  57. [self.dataArr removeAllObjects];
  58. }
  59. NSArray *arr = [NSArray modelArrayWithClass:[BogoChoiceAreaModel class] json:[responseJson valueForKey:@"data"]];
  60. [self.dataArr addObjectsFromArray:arr];
  61. [self.tableView reloadData];
  62. } FailureBlock:^(NSError *error) {
  63. }];
  64. }
  65. #pragma mark - UITableView Datasource
  66. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  67. return 1;
  68. }
  69. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  70. return self.dataArr.count;
  71. }
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  73. BogoChoiceAreaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BogoChoiceAreaCell"];
  74. if (self.dataArr.count > 0) {
  75. cell.model = self.dataArr[indexPath.row];
  76. }
  77. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  78. return cell;
  79. }
  80. #pragma mark - UITableView Delegate methods
  81. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  82. if (self.clickAreaBlock) {
  83. self.clickAreaBlock(self.dataArr[indexPath.row]);
  84. [self clickCancleBtn:nil];
  85. }
  86. }
  87. -(UITextField *)searchField{
  88. if (!_searchField) {
  89. _searchField = [[UITextField alloc]initWithFrame:CGRectMake(kRealValue(12), kTopHeight, kScreenW - kRealValue(12 * 2),kRealValue(32))];
  90. _searchField.placeholder = ASLocalizedString(@"请输入搜索内容");
  91. _searchField.font = [UIFont systemFontOfSize:14];
  92. _searchField.textColor = [UIColor colorWithHexString:@"#AAAAAA"];
  93. _searchField.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
  94. _searchField.layer.cornerRadius = kRealValue(32 / 2);
  95. _searchField.layer.masksToBounds = YES;
  96. UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 33, 33)];
  97. UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 15, 15)];
  98. imageView.image = [UIImage imageNamed:@"bogo_home_top_search"];
  99. imageView.center = leftView.center;
  100. [leftView addSubview:imageView];
  101. _searchField.leftView = leftView;
  102. _searchField.leftViewMode = UITextFieldViewModeAlways;
  103. _searchField.delegate = self;
  104. }
  105. return _searchField;
  106. }
  107. -(UITableView *)tableView{
  108. if (!_tableView) {
  109. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.searchField.bottom, kScreenW, kScreenH - self.searchField.bottom) style:UITableViewStylePlain];
  110. _tableView.delegate = self;
  111. _tableView.dataSource = self;
  112. [_tableView registerNib:[UINib nibWithNibName:@"BogoChoiceAreaCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"BogoChoiceAreaCell"];
  113. _tableView.tableFooterView = [UIView new];
  114. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  115. }
  116. return _tableView;
  117. }
  118. @end