Find when picker view selection changes?
Is there any way I can have an object receive a mes开发者_运维问答sage when the user changes the selected row in the picker view? My pickerview has two components and it is dismissed when the user taps the screen once. But I need to gray out certain options in the second component depending on which option in the first component is chosen.
One other option is to use a timed function to periodically check which row is selected, but that's really hacky. Are there any delegate functions I can use?
Use - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
.
row
tells you what row it is and component
tells you which component it's in.
Remember to include <UIPickerViewDelegate>
in your header file.
UIPickerView has a delegate that you can use, called UIPickerViewDelegate. In it, there is a method called:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
That lets you know what row they've selected and in what component, and should accomplish what you're asking, if I understood correctly.
What about:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent
It's one of UIPickerView's delegates.
You might want to have a look at the UIPickerViewDelegate Protocol
Especially the message might be interesting to you:
pickerView:didSelectRow:inComponent: Called by the picker view when the user selects a row in a component.
精彩评论