3
votes

I was following the advice from Stuart on MVVMCross iOS: how to bind a command with Custom transition when switching to different View model

When I switch to using my custom presenter derived from MvxModalNavSupportTouchViewPresenter then my app crashes (System.NullReferenceException: Object reference not set to an instance of an object) in AppDelegate::FinishedLaunching when calling .Start():

        IMvxAppStart startup = Mvx.Resolve<IMvxAppStart>();
        startup.Start();

Callstack is:

        0x7 in Cirrious.MvvmCross.Touch.Views.Presenters.MvxTouchViewPresenter.get_CurrentTopViewController C#
        0x2 in Cirrious.MvvmCross.Touch.Views.Presenters.MvxTouchViewPresenter.PresentModalViewController   C#
        0x4E in Cirrious.MvvmCross.Touch.Views.Presenters.MvxModalNavSupportTouchViewPresenter.Show C#
        0xB in Cirrious.MvvmCross.Touch.Views.Presenters.MvxTouchViewPresenter.Show C#
        0x28 in Cirrious.MvvmCross.Touch.Views.MvxTouchViewDispatcher.  C#
        0x28 in Cirrious.MvvmCross.Touch.Views.MvxTouchUIThreadDispatcher.RequestMainThreadAction   C#
        0x24 in Cirrious.MvvmCross.Touch.Views.MvxTouchViewDispatcher.ShowViewModel C#
        0x30 in Cirrious.MvvmCross.ViewModels.MvxNavigatingObject.ShowViewModelImpl C#
        0x6 in Cirrious.MvvmCross.ViewModels.MvxNavigatingObject.ShowViewModel  C#
        0xE in Cirrious.MvvmCross.ViewModels.MvxNavigatingObject.ShowViewModel<TestCustomPresenter.Core.ViewModels.FirstViewModel>  C#
        0x17 in Cirrious.MvvmCross.ViewModels.MvxAppStart<TestCustomPresenter.Core.ViewModels.FirstViewModel>.Start C#
    >   0x3A in TestCustomPresenter.iOS.AppDelegate.FinishedLaunching at e:\Src\test\TestCustomPresenter\TestCustomPresenter.iOS\AppDelegate.cs:54  C#
        0x9F in MonoTouch.UIKit.UIApplication.UIApplicationMain C#
        0x52 in MonoTouch.UIKit.UIApplication.Main at /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38   C#
        0x8 in TestCustomPresenter.iOS.Application.Main at e:\Src\test\TestCustomPresenter\TestCustomPresenter.iOS\Main.cs:23   C#

As far as I can tell, there is no current top view controller but I don't know how to set that up as I followed all the steps from Stuart's answer. ( I couldn't reply to his answer as I have 9 rep too few :( )

I've uploaded a test project that reproduces the error to http://www.cliffcawley.net/TestCustomPresenter.zip

What do I have to do to get the example to work and to see the custom transition when you click the button?

1
Thanks - pleese either include the code in the question or link to something browsable online (eg github) if you can - this makes it easier to answer your question while mobile, less likely for the code to disappear and more likely for the question still to make sense in the future :) - Stuart

1 Answers

2
votes

A modal view controller is shown on top of something else. See https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

I haven't downloaded your sample, but from your stack trace my guess is you are showing the modal as your first view - so there's nothing to show it on top of.

An easy solution for this is to try showing another view first - even if it's just a placeholder or backdrop.

Beyond the easy solution, if you are new to uikit, it's worth taking some time to hack a demo app (non-mvx) where you experiment with pushing and popping viewcontrollers as modals, within navigationcontrollers, etc - once you get comfortable with this, then you can quickly write your own navigation/presentation logic in any mvx app.