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  *)self.areasModel.content;
          self.cityArray =  (NSMutableArray *)self.provinceArray[row].childList;
          self.countryArray = (NSMutableArray*)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*)self.cityArray[row].childList;
    
            [pickerView reloadComponent:2];
            [pickerView selectRow:0 inComponent:2 animated:YES];
    
      }
      if(component==2){
          self.selectRow2 = row;
      }
  }
iOS省市区三级联动_第1张图片
屏幕快照 2018-07-10 上午9.42.17.png

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

你可能感兴趣的:(iOS省市区三级联动)