Adding a toolbar onto a picker view for use within a MT.D

nodoidnodoid GBMember, Beta ✭✭✭

I'm re-using the code that worked for putting a UIPickerView onto an entry element (it's on pages 26-28 of Xamarin Mobile App. Dev. for iOS). iOS 7 changed things so the use of ActionSheets was removed and InputView used instead for attaching a UIPickerView to a standard UITextView or UITextField.

Action sheets now have a number of different methods


If I use actionSheet.ShowInView(elem.GetContainerTableView()); the console gives me a pile of throwback and the picker view is truncated so touch events don't work. ShowFrom methods all require a toolbar/tabbar/tabbaritem to display.

My full code looks like this

var elem = new EntryElement(StringUtils.GetString("Implements.Implement"), string.Empty, imp != null ? imp.type : string.Empty);

                    var pickerModel = new PickerModel((IList<string>)impList);
                    var pickerView = new UIPickerView
                        Model = pickerModel,
                        ShowSelectionIndicator = true,
                        Hidden = false,
                        AutoresizingMask = UIViewAutoresizing.All,
                        Frame = new RectangleF(0, 100, bounds.Width, bounds.Height)
                    var toolBar = new UIToolbar
                        BarStyle = UIBarStyle.Black,
                        Translucent = true

                    var action = new UIActionSheet
                        Style = UIActionSheetStyle.BlackTranslucent

                    var doneButton = new UIBarButtonItem(StringUtils.GetString("Common.Done"),
                                         UIBarButtonItemStyle.Done, (s, er) =>
                        action.DismissWithClickedButtonIndex(0, true);

                    toolBar.SetItems(new UIBarButtonItem[]{ doneButton }, true);
                    pickerModel.PickerChanged += (object sender, PickerChangedEventArgs er) =>
                        elem.Value = er.SelectedValue;

                    elem.EntryStarted += delegate
                        action.AddSubviews(new UIView[]{ toolBar, pickerView });
                        action.Frame = new RectangleF(0, 100, 300, 500);
                        pickerView.Frame = new RectangleF(action.Frame.X, action.Frame.Y - 25, action.Frame.Width, 216);

Is there a way to access the InputView directly from a MTD entry element or do I need to go mining down to get to it? Failing that, is there a simple way to fix this code so it works again?


  • nodoidnodoid GBMember, Beta ✭✭✭
    edited June 2014


    var tv = elem.GetContainerTableView();
                            foreach (var tt in elem.GetCell(tv).ContentView.Subviews)
                                if (tt is UITextField)
                                    var tf = tt as UITextField;
                                    tf.InputView = PickerUI.CreateDropList(tv, new UIPickerView(), tf, impList);

    I would rather have used LINQ to get to the textfield directly, but

    var text = elem.GetCell(tv).ContentView.Subviews.FirstOrDefault(t=>t.Subview is UITextField);

    just gave a LINQ Enumerable....

Sign In or Register to comment.