地区选择,数据源搞错了,

1,数据源错了,

 

-(void)adjustProvinceCityFormatByCityId:(int)cId  andProvinceId:(int)pId

{

//    找到省份包含的所有城市

    self.cityArray = [selfcityArrayByProvinCode:pId];

//    定位具体城市

    

    for (int i = 0;i < self.cityArray.count; i++) {

        CommonDistrctInfo *info = [self.cityArrayobjectAtIndex:i];

        if (cId == info.idNumber) {

            [self.pickerViewselectRow:i inComponent:1animated:YES];//定位pickview,数据源是self.cityarray,而这里用的  mcityArray

            currentCityIndex = i;

            break;

              }

    }

//    定位省份

    for (int j = 0; j< self.provinceArray.count; j++) {

        CommonDistrctInfo *infos = [self.provinceArrayobjectAtIndex:j];

        if (infos.idNumber == pId) {

            [self.pickerViewselectRow:j inComponent:0animated:YES];//j 在数组里面的索引

            currentProvinceIndex = j;

            break;

        }

        

    }

    

没有地区时候,做的处理,用省份的第一个,

    if (self.cityArray.count == 0) {

         CommonDistrctInfo *mInfo = [self.provinceArrayobjectAtIndex:0];

        self.cityArray = [self cityArrayByProvinCode:mInfo.idNumber];

    }

    

    

   }

原文地址:https://www.cnblogs.com/guligei/p/3389115.html