|
//
// modifyAreaController.m
// ThePaperBase
//
// Created by Huixin on 15/8/26.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "modifyAreaController.h"
@interface modifyAreaController () <UIPickerViewDataSource, UIPickerViewDelegate> {
NSString *area;
}
@property(nonatomic, strong)UIPickerView *picker;
@property(nonatomic, strong)NSArray *pickerData;
@property(nonatomic, strong)TPCustomButton *confirmBtn;
@end
@implementation modifyAreaController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.titleStr = @"修改地区";
[self.view addSubview:self.picker];
[self.view 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];
}
[self layoutViews];
}
- (void)layoutViews {
[self.picker makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.naviBar.bottom).offset(20);
make.left.equalTo(self.view.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@220);
}];
[self.confirmBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.picker.bottom).offset(20);
make.left.and.right.equalTo(self.picker);
make.height.equalTo(self.confirmBtn.width).multipliedBy(0.15);
}];
}
- (UIPickerView*)picker {
if (!_picker) {
_picker = [[UIPickerView alloc] init];
_picker.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
_picker.delegate = self;
_picker.dataSource = self;
_picker.showsSelectionIndicator = YES;
}
return _picker;
}
- (TPCustomButton*)confirmBtn {
if (!_confirmBtn) {
_confirmBtn = [[TPCustomButton alloc] init];
_confirmBtn.title = @"确认";
[_confirmBtn addTarget:self action:@selector(confirmEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _confirmBtn;
}
#pragma mark - btn event
- (void)confirmEvent:(UIButton*)btn {
if (isBlankString(area)) {
area = self.pickerData[0];
}
NSDictionary *dic = @{@"area":area};
[Remote doJsonAction:0 requestUrl:editUserInfoURL parameter:dic delegate:self];
}
#pragma mark - remote delegate
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responseData {
if (actionTag == 0) {
userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]);
userBO *oriUser = [TPUserDefault instance].userBO;
user.loginType = oriUser.loginType;
[TPUserDefault instance].userBO = user;
[self.navigationController popViewControllerAnimated:YES];
}
}
- (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{
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 40;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel* pickerLabel = (UILabel*)view;
if (!pickerLabel){
pickerLabel = [[UILabel alloc] init];
pickerLabel.font = appFont(TEXT_TWO_LEVELSIZE, NO);
pickerLabel.textAlignment = NSTextAlignmentCenter;
pickerLabel.textColor = [UIColor colorWithHexString:TextBlack];
pickerLabel.backgroundColor = [UIColor clearColor];
}
pickerLabel.text = self.pickerData[row];
return pickerLabel;
}
- (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
|