MonoTouch中的简单UIPickerView(Xamarin)?

P. *_*ami 15 c# objective-c uipickerview xamarin.ios ios

任何人都可以描述如何使用XCode在monotouch中创建UIPickerView并使用示例数据填充它吗?

我确实看过这里的例子:https://github.com/xamarin/monotouch-samples/blob/master/MonoCatalog-MonoDevelop/PickerViewController.xib.cs但这对我来说创建我的UIPickerView并不是很有帮助XCode.这是我到目前为止所拥有的:

public partial class StatusPickerPopoverView : UIViewController
{
    public StatusPickerPopoverView (IntPtr handle) : base (handle)
    {
        pickerStatus = new UIPickerView();
        pickerStatus.Model = new StatusPickerViewModel();
    }

    public StatusPickerPopoverView (): base ()
    {
    }

    public class StatusPickerViewModel : UIPickerViewModel
    {
        public override int GetComponentCount (UIPickerView picker)
        {
            return 1;
        }

        public override int GetRowsInComponent (UIPickerView picker, int component)
        {
            return 5;
        }

        public override string GetTitle (UIPickerView picker, int row, int component)
        {

            return "Component " + row.ToString();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

P. *_*ami 21

所以我基本上找到了答案,这比你想象的更容易waaaaaaaaaaaaaaa!

该模型必须在ViewDidLoad中设置否则将崩溃...这就是为什么它没有正确填充.请记住:在"ViewDidLoad"中设置它.

public partial class StatusPickerPopoverView : UIViewController
{
    public StatusPickerPopoverView (IntPtr handle) : base (handle)
    {
    }

    public override ViewDidLoad()
    {
        base.ViewDidLoad();

        pickerStatus = new UIPickerView();
        pickerStatus.Model = new StatusPickerViewModel();
    }

    public class StatusPickerViewModel : UIPickerViewModel
    {
        public override int GetComponentCount (UIPickerView picker)
        {
            return 1;
        }

        public override int GetRowsInComponent (UIPickerView picker, int component)
        {
            return 5;
        }

        public override string GetTitle (UIPickerView picker, int row, int component)
        {

            return "Component " + row.ToString();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)