我正在现有的 Monotouch 项目中测试 MvvmCross。我想开始将项目分段迁移到 Mvvm。
我可以启动应用程序,它会显示我的第一个 (mvvm) 屏幕。之后,我正在做不同的(非 mvvmcross)事情(加载视图等),我想稍后再移植。
我现在正试图将我的一个观点也移植到 mvvmcross。我创建了一个视图“公共类 TestView:MvxViewController”和一个 ViewModel“公共类 TestViewModel:MvxViewModel”
加载该视图时,应用程序崩溃并出现以下错误:
---Message:
Object reference not set to an instance of an object
---Stack Trace:
at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel (IMvxTouchView touchView) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods+<OnViewCreate>c__AnonStorey3.<>m__9 () [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (IMvxView view, System.Func`1 viewModelLoader) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate (IMvxTouchView touchView) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0
at (wrapper delegate-invoke) <Module>:invoke_void__this___object_EventArgs (object,System.EventArgs)
at Cirrious.CrossCore.Touch.Views.MvxDelegateExtensionMethods.Raise (System.EventHandler eventHandler, System.Object sender) [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.Touch.Views.MvxEventSourceViewController.ViewDidLoad () [0x00000] in <filename unknown>:0
at CatalogMVVMTest.Touch.Views.TestView.ViewDidLoad () [0x0001a] in /Users/matthiasvalcke/Projects/MVVMDemos/CatalogMVVMTest/CatalogMVVMTest.Touch/Views/TestView.cs:20
...
调用“base.ViewDidLoad();”时似乎崩溃了
不确定这是否重要,但在加载第一个视图后,我正在加载一个新的(非 mvvmcross)视图作为导航堆栈的根。
所以现在我正在尝试将 MvvmCross 视图加载到普通的 UIView(Controller)
我也得到以下 Mvx 诊断输出:
mvx: Diagnostic: 1.08 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
编辑:
如果我只是从 MvvmCross 编辑一个简单的示例,我也会得到它。例如,如果我只使用一个“FirstView”和“FirstViewModel”来获取基本样本,然后我做了这样的事情,我会得到错误:
var secondv = new SecondView ();
secondv.View.Frame = new RectangleF (0,250,320,100);
Add (secondv.View);
SecondView 只是一个 MvxViewController。似乎我无法在代码中将视图从 MvxViewController 添加到另一个 MvxViewController。这个对吗?
有人有想法吗?