Ios6 Monotouch CUSTUIPICKER获取所选项目

Ios6 Monotouch CUSTUIPICKER获取所选项目,ios6,xamarin.ios,uipickerview,xamarin,Ios6,Xamarin.ios,Uipickerview,Xamarin,这是我的picker模型课 using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using MonoTouch.Foundation; using MonoTouch.UIKit; namespace Mobile.iOS { public class PickerDataModel : UIPickerViewModel { publi

这是我的picker模型课

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace Mobile.iOS
{
    public class PickerDataModel : UIPickerViewModel
    {
        public event EventHandler<EventArgs> ValueChanged;

        public List<string> Items
        {
            get { return this._items;} 
            set { this._items = value;}
        }
        List<string> _items = new List<string>();

        public string SelectedItem
        {
            get { return this._items[this._selectedIndex]; }
        }
        protected int _selectedIndex = 0;

        public PickerDataModel()
        {   
        }

        public override int GetRowsInComponent (UIPickerView picker, int component)
        {
            return this._items.Count;
        }

        public override string GetTitle (UIPickerView picker, int row, int component)
        {
            return this._items[row];
        }

        public override int GetComponentCount (UIPickerView picker)
        {
            return 1;
        }

        public override void Selected (UIPickerView picker, int row, int component)
        {
            this._selectedIndex = row;
            if (this.ValueChanged != null)
            {
                this.ValueChanged (this, new EventArgs());
            }
        }
    }
}

任何帮助都将不胜感激。提前感谢。

在ActionSheet ChildagePicker中公开您的agePickerDataModel并将其公开

我也会让你的UIButton doneButton在ActionSheet ChildagePicker中公开

    public UIButton doneButton = UIButton.FromType (UIButtonType.RoundedRect);
注释掉ActionSheetChildAgePicker中的按钮事件,以便我们可以在视图控制器中处理它

    doneButton.SetTitleColor(MonoTouch.UIKit.UIColor.White, UIControlState.Normal);
    doneButton.SetTitle ("done", UIControlState.Normal);
    //doneButton.TouchUpInside += (s, e) => { actionSheet.DismissWithClickedButtonIndex    (0, true); };
然后在视图控制器中,您可以执行以下操作

  actionSheetChildAgePicker.doneButton.TouchUpInside += (s, e) => { 
  string sPickedAge = actionSheetChildAgePicker.agePickerDataModel.SelectedItem;
  actionSheetChildAgePicker.Hide(true);
                    };
    doneButton.SetTitleColor(MonoTouch.UIKit.UIColor.White, UIControlState.Normal);
    doneButton.SetTitle ("done", UIControlState.Normal);
    //doneButton.TouchUpInside += (s, e) => { actionSheet.DismissWithClickedButtonIndex    (0, true); };
  actionSheetChildAgePicker.doneButton.TouchUpInside += (s, e) => { 
  string sPickedAge = actionSheetChildAgePicker.agePickerDataModel.SelectedItem;
  actionSheetChildAgePicker.Hide(true);
                    };