Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MvvmCross iOS: NullReference when using a Custom Presenter for Transitions

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?

like image 474
Cliff Cawley Avatar asked Apr 24 '26 00:04

Cliff Cawley


1 Answers

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.

like image 70
Stuart Avatar answered Apr 26 '26 14:04

Stuart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!