views:

338

answers:

2

I'd like to get the row value in real-time as the iPhone user spins a wheel in a UIPickerView (not just when the wheel settles onto a particular row). I looked into subclassing UIPickerView then overriding the mouseDown method, but I couldn't get this to work. Any suggestions would be very much appreciated.

A: 

The UIPickerView dimensions are fairly consistent. Instead of subclassing it, perhaps you could overlay a UIView of your own on top of the picker view, from which you can track and measure dragging motions, before passing those touches down to the picker view.

Alex Reynolds
Except that then you'd have to reverse engineer the amount of spinning that took place for any given drag, after you had let go...
Kendall Helmstetter Gelner
I'm not sure that issue would be any different with the subclassing approach. At least with the `UIView` approach, its code could be reused more easily for other purposes.
Alex Reynolds
True, any approach that looked only at input to the picker view would have the same issue.
Kendall Helmstetter Gelner
+4  A: 

Perhaps try implementing the delegate method:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

You could treat it as a passthrough (just passing back the reusingView parameter) but each time it was called you would know that view was coming on the screen as the user scrolled - then you could calculate how many views offset from this one the center view was.

Kendall Helmstetter Gelner
This worked! Thank you Kendall. Very clever.