iOS省市区三级联动

主要代码:处理在滑动每一列时数据的操作。

/**

 *  pickerView选中代理

 *  @param row        选中的row

 *  @param component 

 */

– (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

    if(component==0)

    {

        self.selectRow0 = row;

        self.selectRow1 = 0;

        self.selectRow2 = 0;        

        self.provinceArray = (NSMutableArray <DHAreasProvinceModel *> *)self.areasModel.content;

        self.cityArray =  (NSMutableArray <DHAreasCityModel*>*)self.provinceArray[row].childList;

        self.countryArray = (NSMutableArray<DHAreasCountryModel*>*)self.cityArray[0].childList;

        [pickerView reloadComponent:1];

        [pickerView selectRow:0 inComponent:1 animated:YES];//默认选择row 0        

        [pickerView reloadComponent:2];

        [pickerView selectRow:0 inComponent:2 animated:YES];

    }

    if(component==1)

    {

        self.selectRow1 = row;

        self.selectRow2 = 0;   

        self.countryArray = (NSMutableArray<DHAreasCountryModel*>*)self.cityArray[row].childList;  

        [pickerView reloadComponent:2];

        [pickerView selectRow:0 inComponent:2 animated:YES];    

    }

    if(component==2){

        self.selectRow2 = row;

    }

}

项目地址:https://github.com/huanghaiyan/AreaPickerView

分享到: 更多

发表评论

电子邮件地址不会被公开。 必填项已用*标注