Hi Bob,

I recently had trouble with the same thing, but figured out you can do it
with gesture recognizers. Here's my implementation:

public class SingleTapGestureRecognizer : UITapGestureRecognizer {
  Action<UITapGestureRecognizer> _onTouch;

  public SingleTapGestureRecognizer(Action<UITapGestureRecognizer> onTouch)
: base() {
    _onTouch = onTouch;
    AddTarget(this, new
MonoTouch.ObjCRuntime.Selector("SingleTapSelector"));
    NumberOfTapsRequired = 1;
  }

  [Export("SingleTapSelector")]
  public void SingleTapSelector(UITapGestureRecognizer sender) {
    _onTouch(sender);
  }

}

You can then do this on your UIPickerView:

_picker.AddGestureRecognizer(new
SingleTapGestureRecognizer((gestureRecognizer) => {
  var location = gestureRecognizer.LocationInView(_picker);
  if (location.X > 10 && location.X < _picker.Frame.Width - 10 &&
location.Y > (_picker.Frame.Height / 2) - (50 / 2) && location.Y <
(_picker.Frame.Height / 2) + (50 / 2)) {
    // get value from picker and dismiss it
  }
}));

(adjust X/Y, etc. if necessary)

Hope this helps.

Mikkel

On Tue, May 29, 2012 at 3:22 PM, bobreck <[email protected]> wrote:

> Hey guys, I have a newbie question that's been bugging me for a while.
>
> I am using a UIPickerView in my application and I have it set to select the
> value when the scrolling stops. That's working great.  However, I've been
> asked to change it so that it doesn't pick when stopped, but when someone
> taps on the value that is currently highlighted by the selector bar.  This
> simple task has been a real problem for me.  I just can't seem to figure
> out
> what I need to do to handle this.  Can anyone point me to, or provide a
> code
> example, so I see what I'm missing?
>
> Thanks,
> Bob
>
> --
> View this message in context:
> http://monotouch.2284126.n4.nabble.com/UIPickerView-and-selecting-a-value-tp4655090.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to