0
votes

I use Storyboard with MvvmCross and Xamarin iOS. A I'm getting exception. Here is stack trace:

{System.Collections.Generic.KeyNotFoundException: Could not find view for Kosht.Core.ViewModels.TutorialViewModel at MvvmCross.Views.MvxViewsContainer.GetViewType (System.Type viewModelType) [0x00081] in :0 at 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 at 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 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/Foundation/NSAction.cs:178 --- End of stack trace from previous location where exception was thrown --- at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/UIKit/UIApplication.cs:79 at 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 /Users/vadimkhadyka/Projects/Kosht/src/Mobile/Kosht.iOS/Main.cs:13 }

My 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();
        }
    }

My 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.
            }
}

If I remove BaseViewController and inherited my TutorialView from MvxViewController, everything works great, but with my base class I'm getting the exception.

1
I am not that familiar with MVVMcross, but dont you need to fallow certain naming convention for the framework to hook up viewmodel with view? I make this assumption because I dont see you using BindingContext anywhereWoj
@Woj probably, I don't see any naming issues. If you see, u r welcome :)Atlantis

1 Answers

0
votes

Change this line

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

To

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

And remove this

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