2017-09-26 4 views

Répondre

1

Vous pouvez attribuer un PickerView à InputView propriété TextField et lui attribuer une barre d'outils à InputAccessoryView, comme ceci:

UIToolbar toolBar = new UIToolbar(new CGRect(0, 0, 320, 44)); 
UIBarButtonItem flexibleSpaceLeft = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace,null,null); 
UIBarButtonItem doneButton = new UIBarButtonItem("OK",UIBarButtonItemStyle.Done,this, new ObjCRuntime.Selector("DoneAction")); 
UIBarButtonItem[] list = new UIBarButtonItem[] { flexibleSpaceLeft, doneButton }; 
toolBar.SetItems(list, false); 

UIPickerView pickerView = new UIPickerView(new CGRect(0, 44, 320, 216)); 
pickerView.DataSource = new MyUIPickerViewDataSource(); 
pickerView.Delegate = new MyUIPickerViewDelegate(); 
pickerView.ShowSelectionIndicator = true; 

textField.InputAccessoryView = toolBar; 
textField.InputView = pickerView; 

Après avoir implémenté votre DataSource et Delegate de la pickerview, il peut travailler l ike ceci:

enter image description here

2

utiliser un ActionSheet

actionSheetButton.TouchUpInside += ((sender, e) => { 

      // Create a new Alert Controller 
      UIAlertController actionSheetAlert = UIAlertController.Create("Action Sheet", "Select an item from below", UIAlertControllerStyle.ActionSheet); 

      // Add Actions 
      actionSheetAlert.AddAction(UIAlertAction.Create("Item One",UIAlertActionStyle.Default, (action) => Console.WriteLine ("Item One pressed."))); 

      actionSheetAlert.AddAction(UIAlertAction.Create("Item Two",UIAlertActionStyle.Default, (action) => Console.WriteLine ("Item Two pressed."))); 

      actionSheetAlert.AddAction(UIAlertAction.Create("Item Three",UIAlertActionStyle.Default, (action) => Console.WriteLine ("Item Three pressed."))); 

      actionSheetAlert.AddAction(UIAlertAction.Create("Cancel",UIAlertActionStyle.Cancel, (action) => Console.WriteLine ("Cancel button pressed."))); 

      // Required for iPad - You must specify a source for the Action Sheet since it is 
      // displayed as a popover 
      UIPopoverPresentationController presentationPopover = actionSheetAlert.PopoverPresentationController; 
      if (presentationPopover!=null) { 
       presentationPopover.SourceView = this.View; 
       presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; 
      } 

      // Display the alert 
      this.PresentViewController(actionSheetAlert,true,null); 
     }); 
+0

qui est similaire, mais pas le même contrôle "spinner" comme sur la photo. Je suis sûr que c'est un contrôle natif? – Darius