显示MvxTabBarViewController时的NullReference mvvmcross ios

时间:2017-07-26 16:45:23

标签: ios xamarin uitabbarcontroller mvvmcross sidebar

我在xCode上制作了一个故事板,并且知道我正在使用Xamarin和 mvvmcross 在visual studio上工作,以使用相同的Core来执行IOS和Android应用程序。 我的StoryBoard有一些视图(包括一些初始视图上的SideBar),它将打开4个视图,为ShowViewModel调用MvxTabBarViewController,每个视图将打开一个不同的选项卡。 / p>

所有导航到该4视图,已完成,现在我有问题显示标签栏...

当我尝试对ShowViewModelMvxTabBarViewController进行简单测试并打开特定标签时,在该标签的ViewDidLoad上,我有错误

  

System.NullReferenceException:未将对象引用设置为实例   对象

我的标签栏的结构都是在故事板上创建的。

以下是 TabBarController 的代码:

[MvxFromStoryboard("Main")]
[MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.PushPanel, true)]
public partial class TabDetailView : MvxTabBarViewController<TabDetailViewModel>
{
    private bool _constructed;

    public TabDetailView(IntPtr handle) : base(handle)
    {
        _constructed = true;

        // need this additional call to ViewDidLoad because UIkit creates the view before the C# hierarchy has been constructed
        ViewDidLoad();
    }

    public TabDetailView()
    {
        _constructed = true;

        // need this additional call to ViewDidLoad because UIkit creates the view before the C# hierarchy has been constructed
        ViewDidLoad();
    }

    public override void ViewDidLoad()
    {
        if (!_constructed)
            return;

        base.ViewDidLoad();

        var vm = (TabDetailViewModel)this.ViewModel;
        if (vm == null)
            return;
    }

}

以下是我想要打开的Tab对应的ViewController的代码:

 [MvxFromStoryboard("Main")]
[MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.PushPanel, true)]
public partial class TabDiaryView : MvxViewController<TabDiaryViewModel>
{
    public TabDiaryView (IntPtr handle) : base (handle)
    {
    }


    public override void ViewDidLoad()
    {
        base.ViewDidLoad(); //HERE IS THE ERROR (NULLREFERENCE)
    }
}

public class Setup : MvxIosSetup
{
    public Setup(MvxApplicationDelegate applicationDelegate, UIWindow window)
        : base(applicationDelegate, window)
    {
    }

    public Setup(MvxApplicationDelegate applicationDelegate, IMvxIosViewPresenter presenter)
        : base(applicationDelegate, presenter)
    {
    }

    protected override IMvxApplication CreateApp()
    {
        return new Core.App();
    }

    protected override IMvxTrace CreateDebugTrace()
    {
        return new DebugTrace();
    }

    protected override IMvxIosViewPresenter CreatePresenter()
    {
        return new MvxSidebarPresenter((MvxApplicationDelegate)ApplicationDelegate, Window);
    }
}

请帮助我!!

0 个答案:

没有答案