Forum Xamarin.iOS

UIPickerView problem

Hey all

I am building an app in Xamarin iOS for a project. What I want to do is add a custom UIPicker to my navigationbar. This custom UIPicker shows both an image and text. This allready works. But the problem is that the options seems to be behind something. I can't really explain it better than that.
I followed the code on this site: https://github.com/xamarin/monotouch-samples/blob/master/MonoCatalog-MonoDevelop/PickerCustomModel.cs

Here is my code:

    private UITextView SetupPicker(UITextView textView)
            {
                //var pickerModel = new PickerModelWithImages(list, images);
                var pickerModel = new CustomPickerModel();

                pickerModel.PickerChanged += (sender, e) =>
                {
                    _selectedOption = e.SelectedValue;
                };

                var picker = new UIPickerView
                {
                    Model = pickerModel,
                    ShowSelectionIndicator = true
                };

                textView = new UITextView(new RectangleF(10, 100, 60, 30))
                {
                    Editable = false
                };

                UIToolbar toolbar = new UIToolbar
                {
                    BarStyle = UIBarStyle.Default,
                    Translucent = true
                };
                toolbar.SizeToFit();

                UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (s, e) =>
                {
                    //This dismisses the picker view and returns control to the main screen.
                    textView.ResignFirstResponder();
                    textView.Text = _selectedOption;
                });

                toolbar.SetItems(new[] { doneButton }, true);

                textView.InputAccessoryView = toolbar;
                textView.InputView = picker;

                return textView;
            }

Here is my ViewDidLoad code:

 public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            UITextView stateTextView = new UITextView();
            UITextView gameOptionTextView = new UITextView();


            UIBarButtonItem[] items = {
                new UIBarButtonItem(
                    NSBundle.MainBundle.LocalizedString("Home", null),
                    UIBarButtonItemStyle.Bordered,
                    delegate
                    {
                        // do whatever you need
                        Console.WriteLine("Custom button clicked!");
                    }),
                new UIBarButtonItem(SetupPicker(state_list,stateTextView)),
                new UIBarButtonItem(SetupPicker(gameOptionTextView)), 
                new UIBarButtonItem(
                    NSBundle.MainBundle.LocalizedString("Graph", null),
                    UIBarButtonItemStyle.Bordered,
                    delegate
                    {

                    })
            };

            NavigationController.NavigationBar.TintColor = UIColor.FromRGBA(255, 196, 196, 255);
            NavigationItem.LeftBarButtonItems = items;
        }

Best Answer

Answers

Sign In or Register to comment.