美文网首页
pickerView自定义三级联动效果实现

pickerView自定义三级联动效果实现

作者: zcc_ios | 来源:发表于2017-12-05 16:36 被阅读22次
    //先上代码 最近太忙了 有空再补效果图和说明
    //
    //  ZCCRegisterStudentInfoViewController.m
    //  MOSOBOStudent
    //
    //  Created by mac on 2017/11/6.
    //  Copyright © 2017年 zcc. All rights reserved.
    //
    
    #import "ZCCRegisterStudentInfoViewController.h"
    #import "ZCCCommon.h"
    #import "UILabel+EXTENSION.h"
    #import "ZCCInputLabelWithItemView.h"
    #import "ZCCToolbarOnPickerView.h"
    #import "ZCCSubmitButton.h"
    
    @interface ZCCRegisterStudentInfoViewController ()<UIScrollViewDelegate, UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource>
    
    //中文名
    @property (nonatomic, weak)ZCCInputLabelWithItemView *chineseNameView;
    //英文名
    @property (nonatomic, weak)ZCCInputLabelWithItemView *englishNameView;
    //生日
    @property (nonatomic, weak)ZCCInputLabelWithItemView *birthdayInputView;
    //生日的日期选择器
    @property (nonatomic, strong)UIDatePicker *birthdayPickerView;
    //身份证号
    @property (nonatomic, weak)ZCCInputLabelWithItemView *idCardNumView;
    //性别
    @property (nonatomic, weak)ZCCInputLabelWithItemView *sexInputView;
    //在读学校
    @property (nonatomic, weak)ZCCInputLabelWithItemView *studySchoolView;
    //选择器 第一次在性别那里用
    @property (nonatomic, strong)UIPickerView *pickerView;
    //工具条
    @property (nonatomic, strong)ZCCToolbarOnPickerView *myToolBar;
    //性别的那个数组
    @property (nonatomic, strong)NSArray *sexArray;
    //当前选中textfield tag
    @property (nonatomic, assign)int currentTextFieldTag;
    //在读学校 (市/区/学校) 数组
    @property (nonatomic, strong)NSArray *studySchoolArray;
    
    //当前 数组
    @property (nonatomic, strong)NSMutableArray *currentPickViewArray;
    
    /* pickerView 中的临时数组 */
    //第一组
    @property (nonatomic, strong)NSMutableArray *firstComponentArray;
    
    //第二组
    @property (nonatomic, strong)NSMutableArray *secondComponentArray;
    
    //第三组
    @property (nonatomic, strong)NSMutableArray *thirdComponentArray;
    
    //年级
    @property (nonatomic, weak)ZCCInputLabelWithItemView *studentGradeView;
    
    
    //父母中文名
    @property (nonatomic, weak)ZCCInputLabelWithItemView *parentsChineseNameView;
    
    //与学员关系
    @property (nonatomic, weak)ZCCInputLabelWithItemView *relationshipWithStuView;
    
    //父母身份证号关系
    @property (nonatomic, weak)ZCCInputLabelWithItemView *parentsIDNumView;
    
    //父母联系电话
    @property (nonatomic, weak)ZCCInputLabelWithItemView *parentsPhoneNumView;
    
    //联系地址
    @property (nonatomic, weak)ZCCInputLabelWithItemView *contactAddressView;
    
    //联系地址数组
    @property (nonatomic, strong)NSArray *contactAddressArray;
    
    
    @end
    
    @implementation ZCCRegisterStudentInfoViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }
    
    - (void)backBtnClicked{
        
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    - (void)addViews{
        
        //滚动view
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT)];
        scrollView.contentSize = CGSizeMake(SCREENWIDTH, SCREENHEIGHT + 1);
        scrollView.delegate = self;
        [self.view addSubview:scrollView];
        
        //返回按钮
        UIButton *navBackBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, 30, 24, 24)];
        [navBackBtn setImage:[[UIImage imageNamed:@"back24"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
        navBackBtn.tintColor = DefaultGrayColor(80);
        navBackBtn.userInteractionEnabled = YES;
        [navBackBtn addTarget:self action:@selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:navBackBtn];
        
        //标题
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, SCREENWIDTH, 18)];
        titleLabel.textColor = [UIColor blackColor];
        titleLabel.text = @"学生信息(*为必填项)";
        [UILabel zcc_textLabel:titleLabel StrColor:[UIColor redColor] withCharacter:@"*"];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont systemFontOfSize:17];
        [scrollView addSubview:titleLabel];
        
        //中文名
        ZCCInputLabelWithItemView *chineseNameView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(titleLabel.frame) + 45, SCREENWIDTH - 50, 75)];
        chineseNameView.itemStr = @"中文名*";
        self.chineseNameView = chineseNameView;
        [scrollView addSubview:chineseNameView];
        
        //英文名
        ZCCInputLabelWithItemView *englishNameView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(chineseNameView.frame) + 35, SCREENWIDTH - 50, 75)];
        englishNameView.itemStr = @"英文名";
        englishNameView.inputTextField.keyboardType = UIKeyboardTypeASCIICapable;
        self.englishNameView = englishNameView;
        [scrollView addSubview:englishNameView];
        
        //出生年月 弹出框为pickerView
        ZCCInputLabelWithItemView *birthdayInputView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(englishNameView.frame) + 35, SCREENWIDTH - 50, 75)];
        birthdayInputView.itemStr = @"出生年月*";
        birthdayInputView.inputTextField.delegate = self;
        birthdayInputView.inputTextField.tag = 1001;
        self.birthdayInputView = birthdayInputView;
        //时间picker
        UIDatePicker *birthdayPickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 216)];
        self.birthdayPickerView = birthdayPickerView;
        birthdayPickerView.datePickerMode = UIDatePickerModeDate;
        birthdayPickerView.backgroundColor = DefaultGrayColor(200);
        birthdayInputView.inputTextField.inputView = birthdayPickerView;
        [birthdayPickerView addTarget:self action:@selector(chooseDate:) forControlEvents:UIControlEventValueChanged];
        [scrollView addSubview:birthdayInputView];
        
        //身份证号
        ZCCInputLabelWithItemView *idCardNumView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(birthdayInputView.frame) + 35, SCREENWIDTH - 50, 75)];
        idCardNumView.itemStr = @"身份证号";
        idCardNumView.inputTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        self.idCardNumView = idCardNumView;
        [scrollView addSubview:idCardNumView];
        
        //选择器
        UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, SCREENHEIGHT, SCREENWIDTH, 216)];
        pickerView.delegate = self;
        pickerView.dataSource = self;
        self.pickerView = pickerView;
        
        //工具条
        ZCCToolbarOnPickerView *myToolBar = [[ZCCToolbarOnPickerView alloc] initWithFrame:CGRectMake(0, SCREENHEIGHT - 20, SCREENWIDTH, 30)];
        self.myToolBar = myToolBar;
        [myToolBar setBarStyle:UIBarStyleDefault];
        
        //性别*
        ZCCInputLabelWithItemView *sexInputView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(idCardNumView.frame) + 35, SCREENWIDTH - 50, 75)];
        sexInputView.itemStr = @"性别*";
        sexInputView.inputTextField.inputView = pickerView;
        sexInputView.inputTextField.inputAccessoryView = myToolBar;
        sexInputView.inputTextField.tag = 1002;
        sexInputView.inputTextField.delegate = self;
        self.sexInputView = sexInputView;
        [scrollView addSubview:sexInputView];
        
        //在读学校
        ZCCInputLabelWithItemView *studySchoolView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(sexInputView.frame) + 35, SCREENWIDTH - 50, 75)];
        studySchoolView.itemStr = @"在读学校 (市/区/学校)";
        studySchoolView.inputTextField.inputView = pickerView;
        studySchoolView.inputTextField.inputAccessoryView = myToolBar;
        studySchoolView.inputTextField.tag = 1003;
        studySchoolView.inputTextField.delegate = self;
        self.studySchoolView = studySchoolView;
        [scrollView addSubview:studySchoolView];
        
        
        ZCCInputLabelWithItemView *studentGradeView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(studySchoolView.frame) + 35, SCREENWIDTH - 50, 75)];
        studentGradeView.itemStr = @"年级";
        self.studentGradeView = studentGradeView;
        [scrollView addSubview:studentGradeView];
        
        //-------------------------------------------
        //标题
        UILabel *titleParentsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(studentGradeView.frame) + 35, SCREENWIDTH, 18)];
        titleParentsLabel.textColor = [UIColor blackColor];
        titleParentsLabel.text = @"学生(乙方)监护人信息(*为必填项)";
        [UILabel zcc_textLabel:titleParentsLabel StrColor:[UIColor redColor] withCharacter:@"*"];
        titleParentsLabel.textAlignment = NSTextAlignmentCenter;
        titleParentsLabel.font = [UIFont systemFontOfSize:17];
        [scrollView addSubview:titleParentsLabel];
        
        //父母中文名
        ZCCInputLabelWithItemView *parentsChineseNameView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(titleParentsLabel.frame) + 35, SCREENWIDTH - 50, 75)];
        parentsChineseNameView.itemStr = @"中文名";
        self.parentsChineseNameView = parentsChineseNameView;
        [scrollView addSubview:parentsChineseNameView];
        
        //与学员关系
        ZCCInputLabelWithItemView *relationshipWithStuView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(parentsChineseNameView.frame) + 35, SCREENWIDTH - 50, 75)];
        relationshipWithStuView.itemStr = @"与学员关系";
        self.relationshipWithStuView = relationshipWithStuView;
        [scrollView addSubview:relationshipWithStuView];
        
        ZCCInputLabelWithItemView *parentsIDNumView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(relationshipWithStuView.frame) + 35, SCREENWIDTH - 50, 75)];
        parentsIDNumView.itemStr = @"身份证号";
        self.parentsIDNumView = parentsIDNumView;
        [scrollView addSubview:parentsIDNumView];
        
        ZCCInputLabelWithItemView *parentsPhoneNumView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(parentsIDNumView.frame) + 35, SCREENWIDTH - 50, 75)];
        parentsPhoneNumView.itemStr = @"联系电话";
        self.parentsPhoneNumView = parentsPhoneNumView;
        [scrollView addSubview:parentsPhoneNumView];
        
        
        //联系地址
        ZCCInputLabelWithItemView *contactAddressView = [[ZCCInputLabelWithItemView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(parentsPhoneNumView.frame) + 35, SCREENWIDTH - 50, 75)];
        contactAddressView.itemStr = @"联系地址(市/(区/县)/详细地址)";
        contactAddressView.inputTextField.inputView = pickerView;
        contactAddressView.inputTextField.inputAccessoryView = myToolBar;
        contactAddressView.inputTextField.tag = 1004;
        contactAddressView.inputTextField.delegate = self;
        self.contactAddressView = contactAddressView;
        [scrollView addSubview:contactAddressView];
    
        
        
    }
    
    #pragma mark -pickerDelegate
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
        NSLog(@"pickerDelegate%d", self.currentTextFieldTag);
        if(self.currentTextFieldTag == 1002){
            //性别
            return 1;
        }else if (self.currentTextFieldTag == 1003 || self.currentTextFieldTag == 1004){
            //        在读学校 (市/区/学校)
            return 3;
        }else{
            return 0;
        }
    }
    
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
        if(self.currentTextFieldTag == 1002){
            //性别
            return self.sexArray.count;
        }else if (self.currentTextFieldTag == 1003 || self.currentTextFieldTag == 1004){
            
            //2 是指pickerView 中间那个
            NSDictionary *menu2Dic = self.currentPickViewArray.firstObject;
            
            NSArray *menu2Array = menu2Dic[@"firstMenuArray"];
            
            if(component == 0){
                return self.currentPickViewArray.count;
            }else if (component == 1){
                
                return menu2Array.count;
                
            }else if (component == 2){
                
                NSDictionary *menu3Dic = menu2Array.firstObject;
                
                NSArray *menu3Array = menu3Dic[@"secondMenuArray"];
                
                return menu3Array.count;
            }
            
        }
        return 0;
    }
    
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
        if(self.currentTextFieldTag == 1002){
            //性别
            
            NSDictionary *dic = _sexArray[row];
            
            return dic[@"sex"];
        }else{
            
            //        NSArray *menu1Array = self.currentPickViewArray.firstObject[@"firstMenuArray"];
            //
            //        NSArray *menu2Array = menu1Array.firstObject[@"secondMenuArray"];
            
            if(component == 0){
                
                NSDictionary *menu1Dic = self.firstComponentArray[row];
                
                return menu1Dic[@"firstMenuName"];
                
            }else if (component == 1){
                
                NSDictionary *menu2Dic = self.secondComponentArray[row];
                
                return menu2Dic[@"secondMenuName"];
                
            }else if (component == 2){
                
                NSDictionary *menu2Dic = self.thirdComponentArray[row];
                
                return menu2Dic[@"itemName"];
            }
            
        }
        
        return @"";
    }
    
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
        /*
         NSArray *menu1Array = self.currentPickViewArray.firstObject[@"firstMenuArray"];
         
         NSArray *menu2Array = menu1Array.firstObject[@"secondMenuArray"];
         */
        
        if(component == 0){
            //滚动了第一组
            //        NSDictionary *menu1Dic = self.currentPickViewArray[row];
            
            //选中的dic是
            
            NSDictionary *dic = self.currentPickViewArray[row];
            
            //所以 第二个array是
            self.secondComponentArray = dic[@"firstMenuArray"];
            
            self.thirdComponentArray = self.secondComponentArray.firstObject[@"secondMenuArray"];
            [self.pickerView selectRow:0 inComponent:1 animated:YES];
            [self.pickerView selectRow:0 inComponent:2 animated:YES];
        }else if (component == 1){
            //滚动了第二组
            //        NSDictionary *menu2Dic = menu1Array[row];
            NSDictionary *secondDic = self.secondComponentArray[row];
            
            self.thirdComponentArray = secondDic[@"secondMenuArray"];
            
            [self.pickerView selectRow:0 inComponent:2 animated:YES];
        }else if (component == 2){
            //滚动了第三组
            //        NSDictionary *menu2Dic = menu2Array[row];
        }
        
        //每一行选中的内容
        NSInteger row1 = [pickerView selectedRowInComponent:0];
        
        NSString *strLine1 = self.firstComponentArray[row1][@"firstMenuName"];
        
        NSInteger row2 = [pickerView selectedRowInComponent:1];
        
        NSString *strLine2 = self.secondComponentArray[row2][@"secondMenuName"];
        
        NSInteger row3 = [pickerView selectedRowInComponent:2];
        
        NSString *strLine3 = self.thirdComponentArray[row3][@"itemName"];
        
        NSString *subStr = [NSString stringWithFormat:@"%@-%@-%@",strLine1, strLine2, strLine3];
        
        if(self.currentTextFieldTag == 1003){
            self.studySchoolView.inputTextField.text = subStr;
        }else if (self.currentTextFieldTag == 1004){
            self.contactAddressView.inputTextField.text = subStr;
        }
        
        [self.pickerView reloadAllComponents];
        
    }
    
    //终止滚动
    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
        
        [self.view endEditing:YES];
        
        if(self.birthdayPickerView.superview){
            
            [self hidBirthdayPicker];
        }
    }
    
    #pragma mark -日期选择开始了
    - (void)chooseDate:(UIDatePicker *)picker{
        
        //把picker 中的 日期 转换成 目标日期
        NSDate *selectedDate = picker.date;
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        formatter.dateFormat = @"yyyy-MM-dd";
        
        NSString *dateString = [formatter stringFromDate:selectedDate];
        
        self.birthdayInputView.inputTextField.text = dateString;
    }
    #pragma mark -textfield delegate
    
    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
        
        if(textField.tag != 1001){
            
            self.currentTextFieldTag = (int)textField.tag;
            
            
            NSLog(@"textfield delegate%d", self.currentTextFieldTag);
            
            if(self.birthdayPickerView.superview){
                [self hidBirthdayPicker];
            }
            //如果是1002
            if(textField.tag == 1002){
                NSLog(@"%@",self.myToolBar.centerItemLabel);
                self.myToolBar.centerItemLabel.text = @"性别";
                
                self.myToolBar.leftItemLabel.text = @"";
                self.myToolBar.rightItemLabel.text = @"";
            }else if(textField.tag == 1003){
                
                //            在读学校 (市/区/学校)
                self.myToolBar.leftItemLabel.text = @"市";
                self.myToolBar.centerItemLabel.text = @"区";
                self.myToolBar.rightItemLabel.text = @"学校";
                
                //重新添加
                self.currentPickViewArray = [NSMutableArray arrayWithArray:self.studySchoolArray];
                
                self.firstComponentArray = self.currentPickViewArray;
                
                //第二组数组(包含江东区 鄞州区的字典)
                NSArray *menu1Array = self.currentPickViewArray.firstObject[@"firstMenuArray"];
                //第三组数组(包含鄞州一中 鄞州二中的字典)
                NSArray *menu2Array = menu1Array.firstObject[@"secondMenuArray"];
                
                self.secondComponentArray = [NSMutableArray arrayWithArray:menu1Array];
                
                self.thirdComponentArray = [NSMutableArray arrayWithArray:menu2Array];
                
            }else if(textField.tag == 1004){
                //联系地址(市/(区/县)/详细地址)
                
                self.myToolBar.leftItemLabel.text = @"市";
                self.myToolBar.centerItemLabel.text = @"区/县";
                self.myToolBar.rightItemLabel.text = @"详细地址";
                
                self.currentPickViewArray = [NSMutableArray arrayWithArray:self.contactAddressArray];
                
                //第一组数据  里面包含 **市的字典
                self.firstComponentArray = self.currentPickViewArray;
                
                //第二组数据 包含上虞区 柯桥区 的字典
                NSArray *menu1Array = self.currentPickViewArray.firstObject[@"firstMenuArray"];
                //第三组数组 里面包含崧厦镇的数组
                NSArray *menu2Array = menu1Array.firstObject[@"secondMenuArray"];
                
                self.secondComponentArray = [NSMutableArray arrayWithArray:menu1Array];
                
                self.thirdComponentArray = [NSMutableArray arrayWithArray:menu2Array];
                
            }
            
            if(self.firstComponentArray.count > 0){
                [self.pickerView selectRow:0 inComponent:0 animated:YES];
            }
            
            if(self.secondComponentArray.count > 0){
                [self.pickerView selectRow:0 inComponent:1 animated:YES];
            }
            
            if(self.thirdComponentArray.count > 0){
                [self.pickerView selectRow:0 inComponent:2 animated:YES];
            }
            
            return YES;
        }
        
        if(self.birthdayPickerView.superview == nil){
            
            [self.view endEditing:YES];
            
            self.birthdayPickerView.frame = CGRectMake( 0, SCREENHEIGHT, SCREENWIDTH, 216);
            [[UIApplication sharedApplication].keyWindow addSubview:_birthdayPickerView];
            
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            
            __weak typeof(self)weakSelf = self;
            
            [UIView animateWithDuration:0.3f animations:^{
                weakSelf.birthdayPickerView.y = (SCREENHEIGHT - 216);
            }];
            return NO;
        }
        
        return NO;
    }
    
    - (void)hidBirthdayPicker{
        
        __weak typeof(self)weakSelf = self;
        [UIView animateWithDuration:0.3f animations:^{
            weakSelf.birthdayPickerView.y = SCREENHEIGHT;
        }];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.birthdayPickerView removeFromSuperview];
        });
    }
    
    - (NSArray *)sexArray{
        
        if(_sexArray == nil){
            
            NSDictionary *dic1 = @{@"sex":@"男", @"code":@"0"};
            NSDictionary *dic2 = @{@"sex":@"女", @"code":@"1"};
            
            _sexArray = [NSArray arrayWithObjects:dic1, dic2, nil];
            
        }
        return _sexArray;
    }
    
    - (NSArray *)studySchoolArray{
        //在读学校 (市/区/学校) 数组 鄞州
        if(_studySchoolArray == nil){
            
            /*
             
             学校编号 1001  1002
             
             区域编号 2001 2001
             
             城市编号 3001 3002
             
             */
            
            //鄞州一中
            NSDictionary *schoolNameDic1 = @{@"itemName":@"鄞州一中", @"itemID": @"1001"};
            //鄞州一中
            NSDictionary *schoolNameDic2 = @{@"itemName":@"鄞州二中", @"itemID": @"1002"};
            
            //第一个区的学校
            NSArray *schoolNameDistrict1Array = @[schoolNameDic1, schoolNameDic2];
            
            NSDictionary *yingZhouDistrict = @{@"secondMenuName": @"鄞州区", @"secondMenuID": @"2001", @"secondMenuArray":schoolNameDistrict1Array};
            
            //江东一中
            NSDictionary *schoolNameDic3 = @{@"itemName":@"江东一中", @"itemID": @"1101"};
            //江东一中
            NSDictionary *schoolNameDic4 = @{@"itemName":@"江东二中", @"itemID": @"1102"};
            
            //第二个区学校
            NSArray *schoolNameDistrict2Array = @[schoolNameDic3, schoolNameDic4];
            
            //第二个区的学校
            NSDictionary *jiangDongDistrict = @{@"secondMenuName": @"江东区", @"secondMenuID": @"2002", @"secondMenuArray": schoolNameDistrict2Array};
            
            NSArray *district1Array = @[yingZhouDistrict, jiangDongDistrict];
            
            //以上第一个市
            NSDictionary *city1Dic = @{@"firstMenuName":@"宁波市", @"firstMenuArray":district1Array};
            
            
            //上虞一中
            NSDictionary *schoolNameDic5 = @{@"itemName":@"上虞一中", @"itemID": @"1201"};
            //上虞二中
            NSDictionary *schoolNameDic6 = @{@"itemName":@"上虞二中", @"itemID": @"1202"};
            
            NSArray *schoolNameDistrict3Array = @[schoolNameDic5, schoolNameDic6];
            
            NSDictionary *shangyuDistrict = @{@"secondMenuName": @"上虞区", @"secondMenuID": @"2003", @"secondMenuArray":schoolNameDistrict3Array};
            
            
            //诸暨一中
            NSDictionary *schoolNameDic7 = @{@"itemName":@"诸暨一中", @"itemID": @"1301"};
            //诸暨二中
            NSDictionary *schoolNameDic8 = @{@"itemName":@"诸暨二中", @"itemID": @"1302"};
            
            NSArray *schoolNameDistrict4Array = @[schoolNameDic7, schoolNameDic8];
            
            //菜单1
            NSDictionary *zhujiDistrict = @{@"secondMenuName": @"诸暨区", @"secondMenuID": @"2004", @"secondMenuArray": schoolNameDistrict4Array};
            //区域
            NSArray *district2Array = @[shangyuDistrict, zhujiDistrict];
            
            //总菜单
            NSDictionary *city2Dic = @{@"firstMenuName":@"绍兴", @"firstMenuArray":district2Array};
            
            
            NSArray *cityArray = @[city1Dic, city2Dic];
            
            _studySchoolArray = cityArray;
        }
        return _studySchoolArray;
    }
    
    #pragma mark 联系地址array
    - (NSArray *)contactAddressArray{
        
        //联系地址(市/(区/县)/详细地址)
        if(_contactAddressArray == nil){
            
            //崧厦镇
            NSDictionary *townNameDic1 = @{@"itemName":@"崧厦镇", @"itemID": @"1001"};
            //上浦镇
            NSDictionary *townNameDic2 = @{@"itemName":@"上浦镇", @"itemID": @"1002"};
            
            //第一个区的镇
            NSArray *townNameDistrict1Array = @[townNameDic1, townNameDic2];
            
            NSDictionary *shangYuDistrict = @{@"secondMenuName": @"上虞区", @"secondMenuID": @"2001", @"secondMenuArray":townNameDistrict1Array};
            
            //柯岩街道  新村镇
            NSDictionary *keYanJieDaoDic3 = @{@"itemName":@"柯岩街道", @"itemID": @"1101"};
            //湖塘街道 柴集镇
            NSDictionary *huTangJieDaoDic4 = @{@"itemName":@"湖塘街道", @"itemID": @"1102"};
            
            //第二个区的镇
            NSArray *townNameDistrict2Array = @[keYanJieDaoDic3, huTangJieDaoDic4];
            
            //第二个区的小镇 阜南
            NSDictionary *keQiaoDistrict = @{@"secondMenuName": @"柯桥区", @"secondMenuID": @"2002", @"secondMenuArray": townNameDistrict2Array};
            
            NSArray *district1Array = @[shangYuDistrict, keQiaoDistrict];
            
            //以上第一个市
            NSDictionary *city1Dic = @{@"firstMenuName":@"绍兴市", @"firstMenuArray":district1Array};
            
            
            //云龙镇
            NSDictionary *townNameDic5 = @{@"itemName":@"云龙镇", @"itemID": @"1201"};
            //姜山镇
            NSDictionary *townNameDic6 = @{@"itemName":@"姜山镇", @"itemID": @"1202"};
            
            NSArray *townNameDistrict3Array = @[townNameDic5, townNameDic6];
            
            NSDictionary *yinZhouQuDistrict = @{@"secondMenuName": @"鄞州区", @"secondMenuID": @"2003", @"secondMenuArray":townNameDistrict3Array};
            
            //白鹤街道
            NSDictionary *townNameDic7 = @{@"itemName":@"白鹤街道", @"itemID": @"1301"};
            //诸暨二中
            NSDictionary *townNameDic8 = @{@"itemName":@"百丈街道", @"itemID": @"1302"};
            
            NSArray *townNameDistrict4Array = @[townNameDic7, townNameDic8];
            
            //菜单1
            NSDictionary *jiangDongDistrict = @{@"secondMenuName": @"江东区", @"secondMenuID": @"2004", @"secondMenuArray": townNameDistrict4Array};
            //区域
            NSArray *district2Array = @[yinZhouQuDistrict, jiangDongDistrict];
            
            //总菜单
            NSDictionary *city2Dic = @{@"firstMenuName":@"宁波市", @"firstMenuArray":district2Array};
            
            
            NSArray *cityArray = @[city1Dic, city2Dic];
            
            _contactAddressArray = cityArray;
        }
        return _contactAddressArray;
        
    }
    
    #pragma mark - 当前数据源  和当前数据下面的三组数据
    - (NSMutableArray *)currentPickViewArray{
        
        if(_currentPickViewArray == nil){
            _currentPickViewArray = [NSMutableArray array];
        }
        
        return _currentPickViewArray;
    }
    
    - (NSMutableArray *)firstComponentArray{
        if(_firstComponentArray == nil){
            _firstComponentArray = [NSMutableArray array];
        }
        return _firstComponentArray;
    }
    
    - (NSMutableArray *)secondComponentArray{
        if(_secondComponentArray == nil){
            _secondComponentArray = [NSMutableArray array];
        }
        return _secondComponentArray;
    }
    
    - (NSMutableArray *)thirdComponentArray{
        
        if(_thirdComponentArray == nil){
            _thirdComponentArray = [NSMutableArray array];
        }
        return _thirdComponentArray;
    }
    
    
    
    @end
    
    

    相关文章

      网友评论

          本文标题:pickerView自定义三级联动效果实现

          本文链接:https://www.haomeiwen.com/subject/gdpcixtx.html