【发布时间】:2017-07-27 08:13:58
【问题描述】:
我正在使用 Xamarin.iOS 和 MvvmCross 5.x。我的根视图是选项卡控制器,我希望任何显示孩子的请求都会强制在选项卡外部(而不是内部)进行堆栈导航。
所以我将我的根视图定义如下:
[MvxFromStoryboard]
[MvxRootPresentation(WrapInNavigationController = true)]
public partial class HomeView : MvxTabBarViewController<HomeViewModel>
不幸的是,根导航控制器不是 UINavigationController(我期望基于属性)而是 HomeView,它本质上是选项卡视图,我无法实现我的目标。
然后我覆盖了 ios Presenter 来手动创建根 UINavigationController:
public class MySuperCoolIosViewPresenter : MvxIosViewPresenter
{
private UINavigationController _rootViewController;
public MySuperCoolIosViewPresenter(IMvxApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
}
protected override void SetWindowRootViewController(UIViewController controller)
{
_rootViewController = new UINavigationController(controller);
base.SetWindowRootViewController(_rootViewController);
}
protected override void ShowChildViewController(UIViewController viewController, MvvmCross.iOS.Views.Presenters.Attributes.MvxChildPresentationAttribute attribute, MvxViewModelRequest request)
{
_rootViewController.ShowViewController(viewController, _rootViewController);
}
}
但是在尝试设置控制器base.SetWindowRootViewController(_rootViewController) 时,此代码在 MvvmCross 深处的某处失败,并出现以下错误:
System.NullReferenceException: Object reference not set to an instance of an object\n
at MvvmCross.iOS.Views.Presenters.MvxIosViewPresenter.CloseTabBarViewController () [0x00036] in <861dee92d7924acc93d876339b4b95f9>:0
at MvvmCross.iOS.Views.MvxTabBarViewController.ViewWillDisappear (System.Boolean animated) [0x0001f] in <861dee92d7924acc93d876339b4b95f9>:0
at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend_IntPtr (intptr,intptr,intptr)
at UIKit.UIWindow.set_RootViewController (UIKit.UIViewController value)
如何在不为根视图创建额外的 ViewModel 和 View 的情况下实现我的目标(我不喜欢这种方法,因为在这种情况下 Android 会崩溃)
【问题讨论】:
标签: ios xamarin.ios uinavigationcontroller mvvmcross