objCを使用すると、UIPickerViewのコンポーネントの数を変更するために使用できるnumberOfComponentsInPickerViewというメソッドがあるようです。これを使用してコンポーネントの数を変更したら、コンポーネントをリロードしてピッカーを「更新」します。すなわち[ピッカーreloadAllComponents];
私の質問は、MonoTouchを使用してこれをどのように行うかです。私はMonoを初めて使用し、ピッカーオブジェクトのすべてのメソッドとプロパティを検索した後、このメソッドが見つからないようです。
UIPickerViewを作成する方法は次のとおりです。
public class PeopleModel : UIPickerViewModel {
static string [] names = new string [] {
"item1",
"item2",
"item3",
"item4",
"item5",
"Custom"
};
ActionSheetPickerExampleViewController pvc;
public PeopleModel (ActionSheetPickerExampleViewController pvc) {
this.pvc = pvc;
}
public override int GetComponentCount (UIPickerView v)
{
return 2;
}
public override int GetRowsInComponent (UIPickerView pickerView, int component)
{
if (component == 0) {
return names.Length;
} else {
return 50;
}
}
public override string GetTitle (UIPickerView picker, int row, int component)
{
if (component == 0)
return names [row];
else
return row.ToString ();
}
public override void Selected (UIPickerView picker, int row, int component)
{
pvc.diskLabel.Text = String.Format ("{0} - {1}",
names [picker.SelectedRowInComponent (0)],
picker.SelectedRowInComponent (1));
Console.WriteLine (names[picker.SelectedRowInComponent(0)]);
if (names [picker.SelectedRowInComponent(0)] == "Custom") {
Console.WriteLine ("Custom selected!");
picker.ReloadComponent(1);
using(var alert = new UIAlertView("Select value", "Select custom disk speed",null,"OK","Button2"))
{
alert.Show ();
}
}
}
public override float GetComponentWidth (UIPickerView picker, int component)
{
if (component == 0)
return 240f;
else
return 40f;
}
public override float GetRowHeight (UIPickerView picker, int component)
{
return 40f;
}
}
上記はクラスです。次に、次のようなアクションシートにピッカーを作成します。
actionSheetPicker = new ActionSheetPicker (this.View);
actionSheetPicker.Title = "Choose disk speed:";
actionSheetPicker.Picker.Model = new PeopleModel (this);
actionSheetPicker.Picker.Hidden = false;
基本的に、最初のコンポーネント列で「カスタム」の値が選択されている場合にのみ、このピッカーに別のコンポーネントを追加し、「カスタム」が選択されている限り、ユーザーがこのコンポーネントから値を選択できるようにすることを検討しています。最初のコンポーネント。これは可能ですか?「GetComponentCount」で別の数を返すことにより、ピッカーが作成される前にコンポーネントの数を変更する方法を知っています。ピッカーが作成されたら、その場でこれを変更するだけですが、よくわかりません。
助けてくれてありがとう!