Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MvvmCross Using a modal ViewController from a Tab

I've searched on SO & elsewhere for MvvmCross & Modal, but the one existing answer isn't helping us.

We're developing a cross-platform app using MonoTouch & MvvmCross, which seems to be pretty powerful combination. However, we're having a few issues with the navigation, which we're gradually cracking! The current problem is -

The app runs with a TabBarController, and each tab has navigation to further levels - this works fine. The client however wants the "Start" button on one of the tabs to bring up a modal view (which hides everything else, especially the tab bar), which then has its own levels working in the same manner as a UINavigationController, with the ability to pop back to the tabBarController at any time.

We've managed to bring up a single modal view, but we're stuck on loading new views from here and popping back out.

Any help/advice appreciated!

like image 203
SomaMan Avatar asked Jun 14 '12 16:06

SomaMan


1 Answers

I think what you're looking to do is to customise the presenter so that it wraps your UIViewController within a UINavigationController - and then modally presents that UINavigationController?

To achieve this, the code in the recent Pull request from @DeapSquatter might help -https://github.com/slodge/MvvmCross/pull/9 - I think you can use his modal nav presenter in order to achieve the effect you are looking for:

        if (view is IMvxModalTouchView)
        {
            if (_currentModalViewController != null)
                throw new MvxException("Only one modal view controller at a time supported");

            var newNav = new UINavigationController();
            newNav.PushViewController(view as UIViewController, false);

            _currentModalViewController = view as UIViewController;

            PresentModalViewController(newNav, true);
            return;
        }

The architecture of mvvmcross is deliberately extensible and configurable here - while we include a few basic Presenter classes, it's very likely that people are going to want to customise how different views get presented on an app-by-app basis. Beyond the simplest of demo apps, I anticipate that most mvvmcross apps on touch will ship with a custom presenter inside.

Hope that helps

Stuart

like image 70
Stuart Avatar answered Sep 23 '22 20:09

Stuart