Mastro
Mastro

Reputation: 1497

How do I use Xamarin iOS PickView to get the value?

I just started messing around with Xamarin and I'm confused on two things. How to use it and if I'm searching the right keywords for help.

If I want to look up something can I look up the native iOS controls as an equivalent? I feel if I search "how to get value from ios picker" the answers are specific to objc-c. Even trying to look at the same properties I have no luck. The Xamarin Tutorials/ documentation I feel are disorganized and lacking. PickView isn't in the list of UI controls that have documentation.

I don't see any events for this PickViewer either in Xamarin Studio. I even try debug mode in Xamarin iOs but almost every property I try and check that seems it might be the answer gives me an "unknown member".

In this example, I have a Xamarin iOs pickviewer and can't figure out how to retrieve the value or even alert on a row selected which doesn't seem to work. I assume I can apply this to a list table as well?

Setting up the PickView list

  public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        pvBankRollAmounts.Model = new UIPickViewBetAmountOptions ();
    }

So how can I get the value of what was selected in the UI? and what's the best way to find these answers on my own? Better Documentation somewhere?

Upvotes: 1

Views: 318

Answers (1)

Jason
Jason

Reputation: 89117

Xamarin iOS sticks pretty closely to the Apple iOS model of doing things. It is actually beneficial to be able to read Obj-C (or Swift) so you can look at Apple's documentation and samples.

Xamarin has a PickerView sample as part of their sample app.

To get the Selected item, you need to override the Selected method in the Model class. This seems strange from a C# perspective, but it is a fairly common pattern in iOS, which commonly uses a Delegate pattern. You could create a custom event and raise it to be handled in your parent class.

public override void Selected (UIPickerView picker, int row, int component)
{
  // row is the selected row
}

Upvotes: 1

Related Questions