1
votes

I have an Xamarin Application with a Android and an IOS version. Since Xamarin Forms now Supports the embedding of Form Pages into native pages I started to build a shared UI. Now I have a Page who shows some informations and intregrated it as fragment on Android which works without issues.

When I try to add it as a Subview on IOS though, it doesn't have any content. I created a new ViewController which inherits from MvxViewController and override the ViewDidLoad and ViewDidLayoutSubviews.

    UIViewController earlyLabelViewController;

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        earlyLabelViewController = new Business.Views.EarlyLabelView { BindingContext = ViewModel }.CreateViewController();
        View.AddSubview(earlyLabelViewController.View);
    }

    public override void ViewDidLayoutSubviews()
    {
        earlyLabelViewController.View.Frame = View.Bounds;
    }

When I add a new Label that works. Also if I just display the view controller with the following code it has the content as well.

PresentViewController(earlyLabelViewController, true, null);

What am I doing wrong that this doesn't show anything?

1

1 Answers

1
votes

I found the solution. I replace the code in the ViewDidAppear Method with the following:

earlyLabelViewController = new Business.Views.EarlyLabelView { BindingContext = ViewModel }.CreateViewController();
earlyLabelViewController.WillMoveToParentViewController(this);
View.Add(earlyLabelViewController.View);
AddChildViewController(earlyLabelViewController);
earlyLabelViewController.DidMoveToParentViewController(this);