Xamarin.iOS中的选择器可用

iOS Picker可用于Xamarin.iOS吗?我一直在搜索,但既没有例子,也没有建立信息;但是,它可以在Xamarin.Form中使用.

解决方法

一个真实的 UIPickerView快速示例:( iOS SDK)

将UIPickerView添加到名为slotMachineView的xib或Storyboard中:

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...