How do you notify a view controller that a line has been selected in UIPickerView?

advertisements

How do I notify my view controller and pass it the string when a row was selected in my UIPickerView?

I have a custom UIPickerView in regular view and I have a custom datasource/delegate in a different class.

How do I notify my view during the pickerView:didSelectRow:inComponent: delegate method? and pass the selected string to the view controller?


The class that is conforming to the picker delegates would implement

pickerView:didSelectRow:inComponent:

to know which row (or string) was selected in the picker.

If some other class from the outside world wants to know which row was selected, then this class in turn needs to inform. This will create a chain of delegation.

For example, if pickerClass is the class that implements the delegate method. If some other class (say outsideClass) wants to know about which row was selected, then you would make this outsideClass delegate of pickerClass and pass on this message to it.

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
[_pickerClassDelegate pickerClass:self didSelectRow:row inComponent:component];
}