Search code examples
iphoneuipickerview

Making two UIPickerView in relation to each other


How do I programmatically setup up the UIPickerView in a view without using Interface Builder? Also having trouble understanding how to do two UIPickerView when I select a value from the first UIPickerView, second UIPickerView change these values? first UIPickerView country and seconde UIPickerView city.


Solution

  • 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)
       {
    
       }
    }