0

iPad で Xamarin モノタッチ アプリを実行すると、UIPickerView が表示されますが、空です。どのデリゲートも起動しません: GetRowsInComponent GetComponentCount GetTitle

ストーリーボードで UIPickerView を作成し、ファイルの所有者に接続しました。

ここに私の.csコードがあります.................

using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;

namespace MainApp
{
    public partial class Ultrasound_Controller : UIViewController
    {

        public Ultrasound_Controller(IntPtr handle)
            : base(handle)                   
        {
        }

        Presets_File_Picker_Model presets_file_picker_model;

        public override void ViewDidLoad()
        {
            Console.WriteLine("ViewDidLoad");
           base.ViewDidLoad();
          }



        public class Presets_File_Picker_Model : UIPickerViewModel
        {
            public event EventHandler<EventArgs> ValueChanged;

            /// <summary>
            /// The color we wish to display
            /// </summary>
            public List<string> Items
            {
                get { return items; }
                set { items = value; }
            }
            List<string> items = new List<string>();

            /// <summary>
            /// The current selected item
            /// </summary>
            public string SelectedItem
            {
                get { return items[selectedIndex]; }
            }
            protected int selectedIndex = 0;

            /// <summary>
            /// default constructor
            /// </summary>
            public Presets_File_Picker_Model()
            {
            }








            public override int GetRowsInComponent(UIPickerView picker, int component)
            {
                Console.WriteLine("GetRowsInComponent");
                return 5;
            }

            public override int GetComponentCount(UIPickerView picker)
            {
                Console.WriteLine("GetComponentCount");
                return 1;
            }

            public override string GetTitle(UIPickerView picker, int row, int component)
            {

                Console.WriteLine("GetTitle");
                return "Component " + row.ToString();
            }


            /// <summary>
            /// called when a row is selected in the spinner
            /// </summary>
            public override void Selected (UIPickerView picker, int row, int component)
            {
                Console.WriteLine("Selected");
                selectedIndex = row;
                if (this.ValueChanged != null)
                {
                    this.ValueChanged (this, new EventArgs ());
                }   
            }
        }
4

1 に答える 1

0

の初期化がどこにも見当たりませんPresets_File_Picker_Model。次ViewDidLoadのようなものが必要です。

this.presets_file_picker_model = new Presets_File_Picker_Model() { Items = new string[] { "one", "two", "three", "four", "five" } };
this.presets_file_picker_model.ValueChanged += HandleValueChanged;
UIPickerView pickerView = new UIPickerView();
pickerView.Model = this.presets_file_picker_model;

次に、コードにハンドラー メソッドを実装します。

HandleValueChanged(object sender, GenericEventArgs<EventArgs> e)
于 2013-10-25T11:15:38.800 に答える