gpt4 book ai didi

c# - MvxTabBarViewController 作为第一个 ViewController 没有出现

转载 作者:行者123 更新时间:2023-11-29 13:54:32 24 4
gpt4 key购买 nike

在我的 Xamarin.iOS 应用程序(使用 MvvmCross)中,我注册了一个自定义 AppStart,它根据用户是否已经登录来启动登录屏幕或主屏幕。我正在使用 EntityFrameworkCore 来存储用户数据并且在启动时从数据库加载信息工作正常,问题出现在调用 await NavigationService.Navigate<MainViewModel() 之后来自 AppStart。

我在调试器中收到 MvvmCross 导航 ( iOSNavigation ) 的消息,紧接着是 Request is null - assuming this is a TabBar type situation where ViewDidLoad is called during construction... patching the request now - but watch out for problems with virtual calls during construction ,据我在网上的研究可以看出,这是正常的。但是,该 View 从未出现,应用程序仍然停留在启动/启动屏幕上。

我的 MainViewController(对应 MainViewModel)继承自 MvxTabBarViewController 并具有以下表示属性:[MvxRootPresentation(AnimationOptions = UIViewAnimationOptions.TransitionCrossDissolve | UIViewAnimationOptions.CurveEaseInOut, WrapInNavigationController = true)] .

MainViewController 的唯一构造函数是:

public MainViewController()
: base()
{
// No call to ViewDidLoad here as base() seems to do it for me.
}

在我的 Xamarin.Android 项目中一切正常,所以我猜它在 iOS 端。

MvvmCross 6.3.1.

编辑

要显示的选项卡在 MainViewController 的 ViewDidLoad 中创建:

public override void ViewDidLoad()
{
base.ViewDidLoad();

if (ViewModel == null)
return;

// There are 3 ViewControllers, all created this way.
var viewControllerOne = new ViewControllerOne
{
ViewModel = ViewModel.ViewModelOne,
TabBarItem = new UITabBarItem(ViewModel.ViewModelOne.Title, UIImage.FromBundle("Icon1"), 0)
};

ViewControllers = new UIViewController[]
{
viewControllerOne,
viewControllerTwo,
viewControllerThree
};
}

每个选项卡都继承自 MvxViewController 并具有 [MvxTabPresentation]呈现属性。每个选项卡的构造函数是:

public ViewControllerOne()    // One, Two, Three
: base("ViewOne", null) // One, Two, Three
{
// None of the tab views currently have any bindings to ViewModels,
just a UILabel constrained to the centre of the view for testing purposes.
}

我尝试在主线程上运行初始导航逻辑,但没有任何区别。这就是我在 MvxAppStart.NavigateToFirstViewModel 中的做法:

await Mvx.IoCProvider.Resolve<IMvxMainThreadAsyncDispatcher>().ExecuteOnMainThreadAsync(() =>
{
if (isLoggedIn)
NavigationService.Navigate<MainViewModel>().GetAwaiter().GetResult();
else
NavigationService.Navigate<LoginViewModel>().GetAwaiter().GetResult();
});

最佳答案

我发现您设置标签的方式存在一些问题。

首先,在您的 ViewDidLoad 中,以下行可能有问题:

    if (ViewModel == null)
return;

你不应该这样做。如果代码执行命中 return;,方法中的其余代码将永远不会执行。

请参阅此处的示例代码:https://github.com/pnavk/Xamarin.iOS.MvvmCross.Tabs

希望对您有所帮助。

关于c# - MvxTabBarViewController 作为第一个 ViewController 没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57411232/

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