簡體   English   中英

MvxTabBarViewController作為第一個ViewController沒有出現

[英]MvxTabBarViewController as first ViewController doesn't appear

在我的Xamarin.iOS應用程序(使用MvvmCross)中,我注冊了一個自定義AppStart,它根據用戶是否已經登錄來啟動登錄屏幕或主屏幕。我正在使用EntityFrameworkCore來存儲用戶數據和加載信息在啟動時從數據庫正常工作,從AppStart調用await NavigationService.Navigate<MainViewModel()后會出現問題。

我在調試器中收到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 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據我從網上的研究中得知, 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是正常的。 但是,視圖永遠不會出現,並且應用程序仍停留在啟動/啟動屏幕上。

我的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;否則, return; ,該方法中的其余代碼將永遠不會執行。

在此處查看示例代碼: https : //github.com/pnavk/Xamarin.iOS.MvvmCross.Tabs

希望能幫助到你。

問題是我的ViewModel邏輯阻塞了主線程。

在我的MainViewModel我重寫了Initialize任務,以從API異步加載數據以顯示各個選項卡。

最初,當我應該使用MvxViewModel方法InvokeOnMainThreadInvokeOnMainThreadAsync時,我使用IMvxMainThreadAsyncDispatcher在主線程上運行事情。 現在,我正在使用這些應用程序,可以正常啟動。

感謝所有嘗試提供幫助的人,特別感謝Cheesebaron為我指出了有關阻塞主線程的正確方向。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM