MvvmCross Xamarin IOS“无法找到ViewModel的视图”

问题描述 投票:0回答:1

我使用Storyboard与MvvmCross和Xamarin iOS。我得到了例外。这是堆栈跟踪:

{System.Collections.Generic.KeyNotFoundException:无法在MvvmCross.View.MvxViewsContainer.GetViewType(System.Type viewModelType)[0x00081]中找到Kosht​​.Core.ViewModels.TutorialViewModel的视图:0,MvvmCross.Presenters.MvxAttributeViewPresenter.GetPresentationAttribute( MvvmCross.ViewModels.MvxViewModelRequest request)[0x0000c] in:0 at MvvmCross.Presenters.MvxAttributeViewPresenter.Show(MvvmCross.ViewModels.MvxViewModelRequest request)[0x00000] in:0 at MvvmCross.Platforms.Ios.Views.MvxIosViewDispatcher + <> c__DisplayClass2_0.b__0 ()[0x0001d] in:0,MvvmCross.Base.MvxMainThreadAsyncDispatcher + <> c__DisplayClass0_0.b__0()[0x00000] in:0 at MvvmCross.Base.MvxMainThreadAsyncDispatcher + <> c__DisplayClass1_0 + <b__0> d.MoveNext()[0x00011] in:0 ---抛出异常的前一个位置的堆栈跟踪结束---在/Library/Frameworks/Xamarin.iOS.framework中的System.Runtime.CompilerServices.AsyncMethodBuilderCore + <> c.b__6_0(System.Object state)[0x00000] /版本/ 11 /Library/Frameworks/Xamarin.iOS中的.14.0.14 / src / Xamarin.iOS / mcs / class / referencesource / mscorlib / system / runtime / compilerservices / AsyncMethodBuilder.cs:1018 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply()[0x00000] .framework / Versions / 11.14.0.14 / src / Xamarin.iOS / Foundation / NSAction.cs:178 ---从抛出异常的先前位置开始的堆栈跟踪结束---在(包装器托管到本机)UIKit。 UIApplication.UIApplicationMain(int,string [],intptr,intptr)在/ Library/Frameworks/Xamarin.iOS中的UIKit.UIApplication.Main(System.String [] args,System.IntPtr principal,System.IntPtr委托)[0x00005] .framework / Versions / 11.14.0.14 / src / Xamarin.iOS / UIKit / UIApplication.cs:79在UIKit.UIApplication.Main(System.String [] args,System.String principalClassName,System.String delegateClassName)[0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/UIKit/UIApplication.cs:63 at Kosht​​.iOS.Application.Main(System.String [] args)[0x00001] in /用户/ v adimkhadyka / Projects / Kosht​​ / src / Mobile / Kosht​​.iOS / Main.cs:13}

我的TutorialView:

[MvxViewFor(typeof(TutorialViewModel))]
    [MvxFromStoryboard("Tutorial")]
    [MvxRootPresentation]
    public partial class TutorialView : BaseViewController<TutorialViewModel>
    {
        public TutorialView() : base("TutorialView", null)
        {
        }

        public override void ViewDidLoad()
        {
            base.NavigationController.NavigationBarHidden = true;
            base.ViewDidLoad();
        }
    }

我的BaseViewController:

    public class BaseViewController<TViewModel> : MvxViewController,  IBaseView<TViewModel> where TViewModel : BaseViewModel
        {
            protected BaseViewController(string nibName, NSBundle bundle) : base(nibName, bundle)
            {
            }

            public BaseViewController(IntPtr handle) : base(handle)
            {
            }

            public BaseViewController()
            {
            }

            public override void ViewDidLoad()
            {
                base.ViewDidLoad();
                // Perform any additional setup after loading the view, typically from a nib.
            }

            public new TViewModel ViewModel => (TViewModel)base.ViewModel;


            public override void DidReceiveMemoryWarning()
            {
                base.DidReceiveMemoryWarning();
                // Release any cached data, images, etc that aren't in use.
            }
}

如果我删除BaseViewController并从TutorialView继承我的MvxViewController,一切都很好,但是我的基类我得到了例外。

c# xamarin xamarin.ios mvvmcross
1个回答
0
投票

改变这一行

public class BaseViewController<TViewModel> : MvxViewController,  IBaseView<TViewModel> where TViewModel : BaseViewModel

public class BaseViewController<TViewModel> : MvxViewController<TViewModel> where TViewModel : class, IMvxViewModel

并删除此

public new TViewModel ViewModel => (TViewModel)base.ViewModel;
© www.soinside.com 2019 - 2024. All rights reserved.