gpt4 book ai didi

ios - MvvmCross Tabs Controller 包装到 UINavigation Controller 中?

转载 作者:行者123 更新时间:2023-12-01 18:39:40 25 4
gpt4 key购买 nike

我正在使用 Xamarin.iOS 和 MvvmCross 5.x。我的 Root View 是选项卡 Controller ,我希望任何显示 child 的请求都会强制在选项卡之外(而不是内部)进行堆栈导航。

所以我将我的 Root View 定义如下:

[MvxFromStoryboard]
[MvxRootPresentation(WrapInNavigationController = true)]
public partial class HomeView : MvxTabBarViewController<HomeViewModel>

不幸的是,根导航 Controller 不是 UINavigationController (正如我所期望的基于属性),而是 HomeView 本质上是选项卡 View ,我无法实现我的目标。

然后我覆盖了 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);
}
}

但是这段代码在尝试设置 Controller 时在 MvvmCross 深处的某个地方失败了 base.SetWindowRootViewController(_rootViewController)出现以下错误:
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)

如何在不为 Root View 创建额外的 ViewModel 和 View 的情况下实现我的目标(我不喜欢这种方法,因为在这种情况下 Android 会崩溃)

最佳答案

我创建了这个示例,其中包含您所需要的内容:https://github.com/rrispoli/SampleTabs

关于ios - MvvmCross Tabs Controller 包装到 UINavigation Controller 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45344972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com