Xamarin.iOS 中的选取器可用 [英] Picker in Xamarin.iOS available
本文介绍了Xamarin.iOS 中的选取器可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
iOS Picker 在 Xamarin.iOS 中是否可用?我已经搜索过,但既没有例子也没有资料;但是,它在 Xamarin.Form 中可用.
解决方案
将 UIPickerView
添加到名为 slotMachineView
的 xib 或 Storyboard:
使用系统;使用 UIKit;命名空间插槽{公共部分类 ViewController : UIViewController{public ViewController (IntPtr handle) : base (handle){}公共覆盖 void ViewDidLoad(){base.ViewDidLoad();slotMachineView.Model = new StackOverflowModel (selectedLbl);}公共覆盖无效 DidReceiveMemoryWarning(){base.DidReceiveMemoryWarning();}}公共类 StackOverflowModel : UIPickerViewModel{静态字符串 [] 名称 = 新字符串 [] {"pscorlib.dll","pscorlib_aot.dll","Mono.PlayScript.dll","PlayScript.Dynamic.dll","PlayScript.Dynamic_aot.dll","PlayScript.Optimization.dll","playshell.exe",psc.exe"};UILabel lbl;公共 StackOverflowModel (UILabel lbl){this.lbl = lbl;}公共覆盖 nint GetComponentCount (UIPickerView v){返回3;}公共覆盖 nint GetRowsInComponent (UIPickerView pickerView, nint 组件){返回名称.长度;}公共覆盖字符串 GetTitle(UIPickerView 选择器、nint 行、nint 组件){开关(组件){案例0:返回名称 [行];情况1:返回行.ToString();案例2:返回新字符串 ((char)('A' + row), 1);默认:抛出新的NotImplementedException();}}公共覆盖无效选定(UIPickerView 选择器,nint 行,nint 组件){lbl.Text = String.Format ("{0} : {1} : {2}",名称 [picker.SelectedRowInComponent (0)],picker.SelectedRowInComponent (1),picker.SelectedRowInComponent (2));}公共覆盖 nfloat GetComponentWidth(UIPickerView 选择器,nint 组件){如果(组件== 0)返回 220f;别的返回 30f;}}}
Is iOS Picker available in the Xamarin.iOS? I have searched throughly but there is neither example nor information has been founded; however, it is available in Xamarin.Form.
解决方案
A real quickie example of a UIPickerView: (iOS SDK)
Add a UIPickerView
to your xib or Storyboard called 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.iOS 中的选取器可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文