ios On new view not loaded in properly

Hello, I'm trying to create an app with different views and controllers. When you push a button on the CustomViewController it should take you to the PickerViewController, and show a picker. However, the picker is not shown on the PickerView page, but instead it is shown only when you are switching between the views.

My CustomViewController is as follows:

public class CustomViewController : UIViewController
    {
        public CustomViewController()
        {
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;
            Title = "Home";

            var btn = UIButton.FromType(UIButtonType.System);
            btn.Frame = new CGRect(20, 200, 280, 44);
            btn.SetTitle("Click Me", UIControlState.Normal);

            var PickerView = new PickerViewController();

            btn.TouchUpInside += (sender, e) => {
                this.NavigationController.PushViewController(PickerView, true);
            };

            View.AddSubview(btn);

        }
    }

When the TouchUpInside is triggered it will take the user to the PickerviewController as follows:

public partial class PickerViewController : UIViewController
    {
        public PickerViewController()
        {
        }

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

            View.BackgroundColor = UIColor.White;
            Title = "Page 2";

            UIPickerView personPicker = new UIPickerView(
                            new CGRect(
                                UIScreen.MainScreen.Bounds.X - UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 230,
                                UIScreen.MainScreen.Bounds.Width,
                                180));
            UILabel personLabel = new UILabel();

            View.AddSubview(personPicker);
            View.AddSubview(personLabel);

            var pickerModel = new PeopleModel(personLabel);

            personPicker.Model = pickerModel;
            personPicker.ShowSelectionIndicator = true;
        }
    }

But the content of the PickerViewController is shown only during the transition between the views, not on the PickerView.

What am I doing wrong? Any help is appreciated!

Sign In or Register to comment.