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 ?
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.
UIPickerViewDelegate
has pickerView:didSelectRow:inComponent:
Better override this function
public override func selectedRow(inComponent component: Int) -> Int {
let index = super.selectedRow(inComponent: component)
//call closure or delegate as you want
return index
}
in UIPickerView class to observe changing in realtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With