gpt4 book ai didi

c# - MonoTouch (Xamarin) 中的简单 UIPickerView?

转载 作者:技术小花猫 更新时间:2023-10-29 10:07:27 26 4
gpt4 key购买 nike

谁能描述我如何使用 XCode 在单点触摸中创建 UIPickerView 并用示例数据填充它?

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

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();
}
}
}

最佳答案

所以我基本上找到了答案,它比你想象的要容易得多!

模型必须在 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();
}
}
}

关于c# - MonoTouch (Xamarin) 中的简单 UIPickerView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15577389/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com