1.在项目根目录下保存存有省市区相关数据的address.json文件;
2.创建继承自弹出视图UpView的类AddressPickView:
#import "UpView.h"
@protocol AddressPickViewDelegate <NSObject>
-(void)didClickSureWithProvince:(NSString *)province City:(NSString *)city Area:(NSString *)area;
@end
@interface AddressPickView : UpView
@property (nonatomic, strong) UIButton *sureBtn;
@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, strong) UIPickerView *pickerView;
@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic, weak)id<AddressPickViewDelegate>delegate;
@end
#import "AddressPickView.h"
@interface AddressPickView ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property (nonatomic, strong)NSArray *provinces;//所有的省份数组
@property (nonatomic, strong)NSString *selectedProvince;//当前选中的省份
@property (nonatomic, strong)NSString *selectedCity;//当前选中的城市
@property (nonatomic, strong)NSString *selectedArea;//当前选中的地区
@end
@implementation AddressPickView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (instancetype)init {
if ([super init]) {
self.dataSource = [self getDataSourceFromJson];
self.provinces = [self getProvincesFromDataSource];
self.selectedProvince = @"北京