我有一个应用程序,我希望用户提交大量数据(想想注册表单)。我没有在屏幕上看到10个选择器视图,而是希望有10个文本字段,当选择时,屏幕上会弹出UIPickerView。选择数据后,UITextField将显示在UIPickerView中选择的选项。
以下是我在线查看一些swift和objective-c实现的代码示例之后的尝试:
partial class ContactController : UIViewController{
UIPickerView ContactTypePicker = new UIPickerView();
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
ContactTypePicker.Hidden = true;
List<string> data = {"test1", "test2", "test3"};
ContactTypePicker.Model = new ListPickerModel(data);
ContactTextField.ShouldBeginEditing = ((textField) => {
ContactTypePicker.Hidden = false;
return true;
});
}
// generic picker class
public class ListPickerModel : UIPickerViewModel{
List<string> _items;
public ListPickerModel(List<string> items){
_items = items;
}
public override nint GetComponentCount(UIPickerView picker){
return 1;
}
public override nint GetRowsInComponent (UIPickerView pickerView, nint component)
{
return _items.Count;
}
public override string GetTitle (UIPickerView pickerView, nint row, nint component)
{
return _items [(int)row].Description;
}
}