How to detect changes on UIPickerView?

tristaf picture tristaf · Apr 2, 2010 · Viewed 26.4k times · Source

I want to detect changes of UIPickerView value.

If UIPickerView respond to addTarget I used a code like this:

-(void) valueChange:(id)sender {
change = YES;

} 

UIPickerView *questionPicker = [[UIPickerView alloc] init]; 
[questionPicker addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];

How can I do same things but in a correct way ?

Answer

Kevin Sylvestre picture Kevin Sylvestre · Apr 2, 2010

If you look at the UIPickerViewDelegate it has:

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

Simply set your picker views delegate and implement this.