美文网首页
iOS省市区三级联动

iOS省市区三级联动

作者: huanghy | 来源:发表于2018-07-10 11:32 被阅读164次

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

 /**
   *  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

相关文章

网友评论

      本文标题:iOS省市区三级联动

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