gpt4 book ai didi

xamarin - Xamarin.iOS中的选择器可用

转载 作者:行者123 更新时间:2023-12-04 13:37:53 26 4
gpt4 key购买 nike

Xamarin.iOS中是否提供iOS Picker?我进行了详尽的搜索,但是没有示例,也没有信息可查。但是,它在Xamarin.Form中可用。

最佳答案

UIPickerView的真实示例示例:(iOS SDK)

enter image description here

UIPickerView添加到您的xib或Storyboard中,称为slotMachineView:

using System;
using UIKit;

namespace Slots
{
public partial class ViewController : UIViewController
{
public ViewController (IntPtr handle) : base (handle)
{
}

public override void ViewDidLoad ()
{
base.ViewDidLoad ();
slotMachineView.Model = new StackOverflowModel (selectedLbl);
}

public override void DidReceiveMemoryWarning ()
{
base.DidReceiveMemoryWarning ();
}
}

public class StackOverflowModel : UIPickerViewModel
{
static string[] names = new string [] {
"pscorlib.dll",
"pscorlib_aot.dll",
"Mono.PlayScript.dll",
"PlayScript.Dynamic.dll",
"PlayScript.Dynamic_aot.dll",
"PlayScript.Optimization.dll",
"playshell.exe",
"psc.exe"
};

UILabel lbl;

public StackOverflowModel (UILabel lbl)
{
this.lbl = lbl;
}

public override nint GetComponentCount (UIPickerView v)
{
return 3;
}

public override nint GetRowsInComponent (UIPickerView pickerView, nint component)
{
return names.Length;
}

public override string GetTitle (UIPickerView picker, nint row, nint component)
{
switch (component) {
case 0:
return names [row];
case 1:
return row.ToString ();
case 2:
return new string ((char)('A' + row), 1);
default:
throw new NotImplementedException ();
}
}

public override void Selected (UIPickerView picker, nint row, nint component)
{
lbl.Text = String.Format ("{0} : {1} : {2}",
names [picker.SelectedRowInComponent (0)],
picker.SelectedRowInComponent (1),
picker.SelectedRowInComponent (2));
}

public override nfloat GetComponentWidth (UIPickerView picker, nint component)
{
if (component == 0)
return 220f;
else
return 30f;
}
}
}

关于xamarin - Xamarin.iOS中的选择器可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33900884/

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