Hello,
You can set the selected value by UIPickerView.Select(nint, nint, Boolean) Method, please refer to the following code: Adding a selected method in the custom UIPickerView
public void DefultSelect(string selectedYear, string selectedMonth)
{
if (this.SelectedYear != null && this.SelectedMonth != null)
{
var yearIndex = yearArray.IndexOf(selectedYear);
var monthIndex = monthArray.IndexOf(selectedMonth);
PickerViewDelegate pickerDelegate = (PickerViewDelegate)this.Delegate;
this.Select(yearIndex, 0, true);
this.Select(monthIndex, 1, true);
}
}
Calling this method in a ViewController for testing
clickbutton.TouchUpInside += delegate
{
//get the selected year and month
customLabel.Text = customPicker.SelectedYear +"-" + customPicker.SelectedMonth;
customPicker.Hidden = true;
};
Setting the default selected value
checkSelectbutton.TouchUpInside += delegate
{
customPicker.Hidden = false;
string[] words = customLabel.Text.Split('-');
string defaultYear = words[0];
string defaultMonth = words[1];
customPicker.DefultSelect(defaultYear, defaultMonth);// set the value, I get the selected value from the Label, you can store the value (and get the value) according to your needs
};
Best Regards, Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.