// // YXAddressViewController.m // Temperature // // Created by TC on 2025/3/23. // #import "YXAddressViewController.h" #import "BRAddressPickerView.h" @interface YXAddressViewController () @property (weak, nonatomic) IBOutlet UIView *cityBgView; @property (weak, nonatomic) IBOutlet UILabel *cityLabel; @property (weak, nonatomic) IBOutlet UIView *addressBgView; @property (weak, nonatomic) IBOutlet UITextField *addressTextField; @property (weak, nonatomic) IBOutlet UIButton *sureBtn; @property (nonatomic,copy) NSString *province; @property (nonatomic,copy) NSString *city; @property (nonatomic,copy) NSString *area; @end @implementation YXAddressViewController - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"家庭地址"; NSString *pStr = self.oldProvince.length > 0 ? self.oldProvince : @""; NSString *cStr = self.oldCity.length > 0 ? self.oldCity : @""; NSString *aStr = self.oldArea.length > 0 ? self.oldArea : @""; self.province = pStr; self.city = cStr; self.area = aStr; self.cityLabel.text = [NSString stringWithFormat:@"%@ %@ %@", pStr, cStr, aStr]; self.addressTextField.text = self.oldDetail; UITapGestureRecognizer *cityTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedCity)]; [self.cityBgView addGestureRecognizer:cityTap]; [self.sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:UIControlEventTouchUpInside]; } -(void)sureBtnAction:(UIButton *)btn { if (self.province == nil || self.city == nil || self.area == nil) { [RDSHudShower showBottomToast:@"请选择所在区域"]; return; } if (self.addressTextField.text == nil) { [RDSHudShower showBottomToast:@"请输入详细地址"]; return; } if (self.sureBtnClick) { self.sureBtnClick(self.province, self.city, self.area, self.addressTextField.text); } [self.navigationController popViewControllerAnimated:YES]; } -(void)selectedCity { RDS_WEAKSELF(weakSelf) BRAddressPickerView *addressPickerView = [[BRAddressPickerView alloc]init]; addressPickerView.pickerMode = BRAddressPickerModeArea; addressPickerView.title = @"请选择地区"; addressPickerView.selectValues = @[@"山东省", @"济南市", @"历下区"]; // addressPickerView.selectIndexs = @[@10, @0, @4]; addressPickerView.isAutoSelect = YES; addressPickerView.resultBlock = ^(BRProvinceModel *province, BRCityModel *city, BRAreaModel *area) { NSLog(@"选择的值:%@", [NSString stringWithFormat:@"%@ %@ %@", province.name, city.name, area.name]); weakSelf.province = province.name; weakSelf.city = city.name; weakSelf.area = area.name; weakSelf.cityLabel.text = [NSString stringWithFormat:@"%@ %@ %@", province.name, city.name, area.name]; }; [addressPickerView show]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.addressTextField resignFirstResponder]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end