8

I'm trying to figure out why I get an error message about not being able to find the right ViewModel when I'm running my iOS app.

The question I have is when I look at this example I don't understand where MainMenuView gets bound to MainMenuViewModel.

Can someone answer this for me?

Thanks,

PkL728

PkL728
  • 955
  • 8
  • 21

4 Answers4

9

They are bound by class names: for XXXView should be corresponded XXXViewModel

Roman Kagan
  • 464
  • 1
  • 3
  • 12
  • So in my iOS project I have a ProductsView class which extends MvxTableViewController and in my core project I have a ProductsViewModel class. When I run my program I get this error: Failed to load ViewModel for type LoginProductsMVVM.Core.ViewModels.ProductsViewModel from locator MvxDefaultViewModelLocator... Do I have this set up wrong? – PkL728 Jul 11 '13 at 19:56
  • Ok... so my error was related to a method being called in my ProductsViewModel constructor that was erroring out. Not a helpful error message!! Thanks Roman! – PkL728 Jul 11 '13 at 20:09
  • 2
    Make sure you have trace turned on - http://stackoverflow.com/questions/17233922/mvvmcross-mvx-trace-usage/17234083#17234083 - then you'll see more of the 'not helpful' error message. – Stuart Jul 11 '13 at 21:19
  • OMG. Wasted 2 days due to this. – GeneCode Mar 30 '17 at 05:28
  • Name convention is the default setting. There are several ways to override it: https://www.mvvmcross.com/documentation/fundamentals/Customizing-using-App-and-Setup#overriding-view-viewmodel-associations – Felix Oct 06 '17 at 04:35
1

Just want to add to the answer: double-check the names of the views after renaming (even Resharper renaming is not perfect). Spent several dozens of minutes (and a beer can), catching similar MvvmCross's error Could not find view for %ViewModelName%.

Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64
1

I'm getting this on a project that I've just upgraded to MvvmCross 4. I don't have much experience with MvvmCross, and the project hasn't been maintained for a few years, so it's possible something else is wrong.

I ended up hard coding the mappings in Setup::InitializeViewLookup because I don't have time to waste on it anymore.

jyoung
  • 322
  • 3
  • 13
1

For anyone who ends up here having the same problem I had. I was getting this error in an Android project because my (properly named) view was extending Activity and not MvxActivity (happens easily when you use Xamarin Studio's "Add Android Activity" feature)

Dennis K
  • 1,828
  • 1
  • 16
  • 27