当我在 iPad 上运行 Xamarin monotouch 应用程序时,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 ());
}
}
}