Question

I have a picker that shows the selected value in a text label.

I would like that label to get updated each time the picker value changes. At the moment if I change the value, press Done on the picker, then go to reselect only then it chose the value.

Any ideas how - i get the text from the picker using:

NSString *selectedItem =[_myArray objectAtIndex:[_myPicker selectedRowInComponent:0]];
Was it helpful?

Solution

Implement the delegate method, pickerView:didSelectRow:inComponent:. This is called by the picker view when you select an item. Get the value from your array based on the row and component, and populate your label.

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    self.label.text = _myArray[row];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top