使两个UIPickerView相互关联

时间:2013-06-26 13:36:58

标签: iphone uipickerview

如何在不使用Interface Builder的情况下以编程方式在视图中设置UIPickerView?当我从第一个UIPickerView中选择一个值,第二个UIPickerView更改这些值时,也无法理解如何执行两个UIPickerView? 第一个UIPickerView国家/地区和第二个UIPickerView城市。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

Yes possible you can create array on city within country like
int select=0;

(
   india
       (
         city,
         .....,
       )
   Australia
       (
         City,
         ......,
    )
)

and use
picker

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
   if(picker==1)
   {
     return [arr_counry count];
   }
   else if(picker==2)
   {
     return [[arr_counry objectAtIndex:select] count];
   }

}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
  if(picker==1)
   {
     select=[arr_currency objectAtIndex:row];
    [picker reloadAllComponents];

   }
   else if(picker==2)
   {

   }
}