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;
      }
  }
屏幕快照 2018-07-10 上午9.42.17.png

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容