0

I need to perform some code when the user stop scrolling the picker, in other way, when the picker stop scrolling. The logic i want to follow is, once the picker stop scrolling, i get the current value and i do some database queries basing on that value.

In the picker view documentation, i don't see a delegate method that can help on such task. Any thoughts? thanx in advance.

Hiren
  • 12,720
  • 7
  • 52
  • 72
Luca
  • 20,399
  • 18
  • 49
  • 70

2 Answers2

2

whenever you scroll the picker view, didSelect delegate method call at the end of scroll

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

NSLog(@"Selected  %i. ",  row);
/// do it here your queries
}

try with above example and check your console

Hiren
  • 12,720
  • 7
  • 52
  • 72
  • Hi, thanx for the reply, actually `row` is of type integer, so it would be `NSLog(@"Selected %i. ", row);` – Luca Mar 23 '12 at 10:39
  • actually almost, i needed the value and not the row index, so it was solved like this: `- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ NSInteger selectedRow=[themeList selectedRowInComponent:0]; NSString *item=[pickerArrayThemesList objectAtIndex:selectedRow]; NSLog(@"%@",item); } ` – Luca Mar 23 '12 at 13:12
  • The solution you give is for retrieving the index of the selected, in my case i need the value itself, so i solved getting the value from the array `pickerArrayThemesList ` which its elements have been put on the picker. Thanx for your help :) – Luca Mar 23 '12 at 13:14
  • hi what's the pickerArrayThemesList? – Hiren Mar 26 '12 at 04:45
  • It's an NSArray and contains the elements of the picker, so in the `titleForRow` data source method, i used it to identify the elements of the picker. – Luca Mar 26 '12 at 08:17
1

The delegate class has a method pickerView:didSelectRow:inComponent:, that you can use to detect the selected row.

sch
  • 27,436
  • 3
  • 68
  • 83