澎湃iPad上线版本

modifyAreaController.m 7.2KB

    // // modifyAreaController.m // ThePaperHD // // Created by scar1900 on 15/3/29. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "modifyAreaController.h" #import "MLNavigationController.h" #import "KGModal.h" #import "TPCustomButton.h" @interface modifyAreaController ()<UIPickerViewDataSource,UIPickerViewDelegate> { NSString *area; } @property(nonatomic, strong)UIButton *closeBtn; @property(nonatomic, strong)UILabel *titleLabel; @property(nonatomic, strong)TPCustomButton *confirmBtn; @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UIPickerView *picker; @property(nonatomic, strong)NSArray *pickerData; @end @implementation modifyAreaController @synthesize pickerData; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor clearColor]; self.view.frame = CGRectMake(0, 0, loginPopUpSize.width, loginPopUpSize.height); [self.view addSubview:self.closeBtn]; [self.view addSubview:self.titleLabel]; self.closeBtn.frame = CGRectMake(0, 0, 50, 80); [self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)]; self.titleLabel.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 80); [self.view addSubview:self.backView]; [self.backView addSubview:self.picker]; [self.backView addSubview:self.confirmBtn]; self.pickerData = [NSArray arrayWithObjects:@"上海",@"北京",@"天津",@"重庆",@"河北",@"河南",@"云南",@"辽宁",@"黑龙江",@"湖南",@"安徽",@"江苏",@"山东",@"新疆",@"浙江",@"江西",@"湖北",@"广西",@"甘肃",@"山西",@"内蒙古",@"陕西",@"吉林",@"福建",@"贵州",@"广东",@"青海",@"西藏",@"四川",@"宁夏",@"海南",@"台湾",@"香港",@"澳门", nil]; [self.picker reloadAllComponents]; area = [TPUserDefault instance].userBO.area; if (!isBlankString(area)) { __block NSInteger selectIndex; [pickerData enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([area isMatchedByRegex:obj]) { selectIndex = idx; } }]; [self.picker selectRow:selectIndex inComponent:0 animated:NO]; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBarHidden = YES; [KGModal sharedInstance].tapOutsideToDismiss = NO; } - (UIButton*)closeBtn { if (!_closeBtn) { _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_closeBtn setImage:Image(@"login/popUpBack.png") forState:UIControlStateNormal]; [_closeBtn setImage:Image(@"login/popUpBack_h.png") forState:UIControlStateHighlighted]; [_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _closeBtn; } - (UILabel*)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textAlignment = NSTextAlignmentCenter; _titleLabel.text = @"修改地区"; _titleLabel.textColor = [UIColor whiteColor]; _titleLabel.font = appFont(30, NO); } return _titleLabel; } - (UIView*)backView { if (!_backView) { _backView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), loginPopUpSize.width, loginPopUpSize.height-80)]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } - (UIPickerView*)picker { if (!_picker) { _picker = [[UIPickerView alloc]initWithFrame:CGRectMake(15, 115/2, loginPopUpSize.width-30, 440/2)]; _picker.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _picker.delegate = self; _picker.dataSource = self; _picker.showsSelectionIndicator = YES; } return _picker; } - (TPCustomButton*)confirmBtn { if (!_confirmBtn) { _confirmBtn = [[TPCustomButton alloc]initWithFrame:CGRectMake(190/2, CGRectGetMaxY(self.picker.frame)+20, loginPopUpSize.width-190, 40)]; _confirmBtn.title = @"确 认"; [_confirmBtn addTarget:self action:@selector(confirmEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _confirmBtn; } #pragma mark - btn event - (void)closeEvent:(UIButton*)btn { [(MLNavigationController*)self.navigationController popViewControllerWithFlip]; } - (void)confirmEvent:(UIButton*)btn { if (area.length == 0 && isBlankString(area)) { //bug:3893 area = self.pickerData[0]; } NSDictionary *dic = @{@"area":area}; __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:0 requestUrl:editUserInfoURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]); userBO *oriUser = [TPUserDefault instance].userBO; user.loginType = oriUser.loginType; [TPUserDefault instance].userBO = user; [(MLNavigationController*)Self.navigationController popViewControllerWithFlip]; }else { ShowTextMessage(message); } }]; } #pragma mark - picker delegate and dataSource - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return self.pickerData.count; } - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component { return pickerView.frame.size.width; } - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component { return 44; } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { return self.pickerData[row]; } - (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component { NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:self.pickerData[row] attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextBlack]}]; return atrString; } - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { area = self.pickerData[row]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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