YXAddressViewController.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // YXAddressViewController.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/3/23.
  6. //
  7. #import "YXAddressViewController.h"
  8. #import "BRAddressPickerView.h"
  9. @interface YXAddressViewController ()
  10. @property (weak, nonatomic) IBOutlet UIView *cityBgView;
  11. @property (weak, nonatomic) IBOutlet UILabel *cityLabel;
  12. @property (weak, nonatomic) IBOutlet UIView *addressBgView;
  13. @property (weak, nonatomic) IBOutlet UITextField *addressTextField;
  14. @property (weak, nonatomic) IBOutlet UIButton *sureBtn;
  15. @property (nonatomic,copy) NSString *province;
  16. @property (nonatomic,copy) NSString *city;
  17. @property (nonatomic,copy) NSString *area;
  18. @end
  19. @implementation YXAddressViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.navigationItem.title = @"家庭地址";
  23. NSString *pStr = self.oldProvince.length > 0 ? self.oldProvince : @"";
  24. NSString *cStr = self.oldCity.length > 0 ? self.oldCity : @"";
  25. NSString *aStr = self.oldArea.length > 0 ? self.oldArea : @"";
  26. self.province = pStr;
  27. self.city = cStr;
  28. self.area = aStr;
  29. self.cityLabel.text = [NSString stringWithFormat:@"%@ %@ %@", pStr, cStr, aStr];
  30. self.addressTextField.text = self.oldDetail;
  31. UITapGestureRecognizer *cityTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedCity)];
  32. [self.cityBgView addGestureRecognizer:cityTap];
  33. [self.sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  34. }
  35. -(void)sureBtnAction:(UIButton *)btn
  36. {
  37. if (self.province == nil || self.city == nil || self.area == nil) {
  38. [RDSHudShower showBottomToast:@"请选择所在区域"];
  39. return;
  40. }
  41. if (self.addressTextField.text == nil) {
  42. [RDSHudShower showBottomToast:@"请输入详细地址"];
  43. return;
  44. }
  45. if (self.sureBtnClick) {
  46. self.sureBtnClick(self.province, self.city, self.area, self.addressTextField.text);
  47. }
  48. [self.navigationController popViewControllerAnimated:YES];
  49. }
  50. -(void)selectedCity
  51. {
  52. RDS_WEAKSELF(weakSelf)
  53. BRAddressPickerView *addressPickerView = [[BRAddressPickerView alloc]init];
  54. addressPickerView.pickerMode = BRAddressPickerModeArea;
  55. addressPickerView.title = @"请选择地区";
  56. addressPickerView.selectValues = @[@"山东省", @"济南市", @"历下区"];
  57. // addressPickerView.selectIndexs = @[@10, @0, @4];
  58. addressPickerView.isAutoSelect = YES;
  59. addressPickerView.resultBlock = ^(BRProvinceModel *province, BRCityModel *city, BRAreaModel *area) {
  60. NSLog(@"选择的值:%@", [NSString stringWithFormat:@"%@ %@ %@", province.name, city.name, area.name]);
  61. weakSelf.province = province.name;
  62. weakSelf.city = city.name;
  63. weakSelf.area = area.name;
  64. weakSelf.cityLabel.text = [NSString stringWithFormat:@"%@ %@ %@", province.name, city.name, area.name];
  65. };
  66. [addressPickerView show];
  67. }
  68. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  69. {
  70. [self.addressTextField resignFirstResponder];
  71. }
  72. /*
  73. #pragma mark - Navigation
  74. // In a storyboard-based application, you will often want to do a little preparation before navigation
  75. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  76. // Get the new view controller using [segue destinationViewController].
  77. // Pass the selected object to the new view controller.
  78. }
  79. */
  80. @end