Search code examples
iphoneobjective-ciosuipickerview

UIPickerView change selected item at runtime


I have a UIPickerView where I load an NSMutableArray *column in it. In the *column array, I have a few UIImageViews as array's objects. At runtime, I would like to change the SELECTED item's image ONLY while maintaining the other's item's image. How can I do this? I can get the row of selected item with:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

}

But kinda stuck here. Any ideas?


Solution

  • You need to change your source array and reload that component ( column ) such as :

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
           [column replaceObjectAtIndex:row withObject:[UIImage imageName@"YourImage.png"]];
           [pickerView reloadComponent:component];
    
    }