首页 文章

嵌入式Xamarin.Forms在IOS上查看为空

提问于
浏览
0

我有一个带有Android和IOS版本的Xamarin应用程序 . 由于Xamarin Forms现在支持将表单页面嵌入本机页面,因此我开始构建共享UI . 现在我有一个页面显示一些信息,并将其作为片段在Android上进行整理,无问题 .

当我尝试在IOS上添加它作为子视图时,它没有任何内容 . 我创建了一个新的ViewController,它继承自MvxViewController并覆盖ViewDidLoad和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;
    }

当我添加一个有效的新标签时 . 此外,如果我只使用以下代码显示视图控制器,它也具有内容 .

PresentViewController(earlyLabelViewController, true, null);

我做错了什么,这没有显示任何东西?

1 回答

  • 0

    我找到了解决方案 . 我用以下代码替换ViewDidAppear方法中的代码:

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

相关问题