Tabs MvvmCross Tab navigation在尝试显示没有TabBarViewController的选项卡时引发异常,这是不可能的
我正在尝试使用最新的MvvmCross 5.x在iOS项目中创建选项卡导航,但我收到的异常消息是: “试图在没有TabBarViewController的情况下显示选项卡,这是不可能的!”Tabs MvvmCross Tab navigation在尝试显示没有TabBarViewController的选项卡时引发异常,这是不可能的,tabs,navigation,mvvmcross,Tabs,Navigation,Mvvmcross,我正在尝试使用最新的MvvmCross 5.x在iOS项目中创建选项卡导航,但我收到的异常消息是: “试图在没有TabBarViewController的情况下显示选项卡,这是不可能的!” 有人能解释一下,可能有什么问题吗?或者有没有任何简单的项目示例来说明如何在iOS项目中使用最新的MvvmCross 5.x版本进行选项卡导航 这是我的代码: [注册(“主视图”)] [MvxRootPresentation(WrapInNavigationController=true)] 公共类主视图:
有人能解释一下,可能有什么问题吗?或者有没有任何简单的项目示例来说明如何在iOS项目中使用最新的MvvmCross 5.x版本进行选项卡导航 这是我的代码:
[注册(“主视图”)]
[MvxRootPresentation(WrapInNavigationController=true)]
公共类主视图:MvxTabBarViewController
{
}
[MVXTAB2演示文稿]
公共部分类HomeView:MvxViewController
{
}
公共类IosViewPresenter:MvxIosViewPresenter
{
公共覆盖无效显示(IMvxIosView视图、MvxViewModelRequest请求)
{
//此行被调用,但引发异常,抱怨TabBarController为null。
显示(查看、请求);
}
}
[注册(“AppDelegate”)]
公共类AppDelegate:MvxApplicationDelegate
{
公共覆盖bool FinishedLaunching(UIApplication应用程序、NSDictionary启动选项)
{
窗口=新的UIWindow(UIScreen.MainScreen.Bounds);
var设置=新设置(此窗口);
setup.Initialize();
var start=Mvx.Resolve();
start.start();
EnsureInitialized(GetType());
Window.MakeKeyAndVisible();
返回true;
}
}
公共类设置:MvxIosSetup
{
受保护的覆盖IMvxIosViewPresenter CreatePresenter()
{
var viewModelLoader=new MvxViewModelLoader();
Mvx.RegisterSingleton(()=>viewModelLoader);
var presenter=新IosViewPresenter((MvxApplicationDelegate)ApplicationDelegate,窗口,viewModelLoader);
Mvx.RegisterSingleton(演示者);
返回演讲者;
}
}
在导航到HomeView之前,您需要导航到MainView,因此不要使用:var start=Mvx.Resolve();start.start();它应该导航到MainViewModel,我应该将IMvxAppStart指向类似FirstViewModel的内容,然后在FirstViewModel内部导航到MainViewModel。这就是你的建议吗?我也遇到了同样的问题,所以我决定直接添加MvvmCross类库进行调试,看看发生了什么。奇怪的是,当时我不再有这个问题了。演示者正确存储了对选项卡栏控制器的引用,这在演示选项卡时是必需的。在导航到HomeViewSo之前,您需要导航到MainView,而不是使用:var start=Mvx.Resolve();start.start();它应该导航到MainViewModel,我应该将IMvxAppStart指向类似FirstViewModel的内容,然后在FirstViewModel内部导航到MainViewModel。这就是你的建议吗?我也遇到了同样的问题,所以我决定直接添加MvvmCross类库进行调试,看看发生了什么。奇怪的是,当时我不再有这个问题了。演示者正确存储了对选项卡栏控制器的引用,这在演示选项卡时是必需的。
[Register("MainView")]
[MvxRootPresentation(WrapInNavigationController = true)]
public class MainView : MvxTabBarViewController<MainViewModel>
{
}
[MvxTabPresentation]
public partial class HomeView : MvxViewController<HomeViewModel>
{
}
public class IosViewPresenter : MvxIosViewPresenter
{
public override void Show(IMvxIosView view, MvxViewModelRequest request)
{
// This line gets called, but raises exception complaining that TabBarController is null.
base.Show(view, request);
}
}
[Register ("AppDelegate")]
public class AppDelegate : MvxApplicationDelegate
{
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
Window = new UIWindow(UIScreen.MainScreen.Bounds);
var setup = new Setup(this, Window);
setup.Initialize();
var start = Mvx.Resolve<IMvxAppStart>();
start.Start();
setup.EnsureInitialized(GetType());
Window.MakeKeyAndVisible();
return true;
}
}
public class Setup : MvxIosSetup
{
protected override IMvxIosViewPresenter CreatePresenter()
{
var viewModelLoader = new MvxViewModelLoader();
Mvx.RegisterSingleton<IMvxViewModelLoader>(() => viewModelLoader);
var presenter = new IosViewPresenter((MvxApplicationDelegate)ApplicationDelegate, Window, viewModelLoader);
Mvx.RegisterSingleton<IMvxIosViewPresenter>(presenter);
return presenter;
}
}