How do I specify a view to be pushed as Modal in MvvmCross?

徘徊边缘 提交于 2019-12-21 05:31:30

问题


I have a view in a MonoTouch app using MvvmCross framework that I would like displayed Modal (NavigationController.PresentModalViewController).


回答1:


MvvmCross starts from the premise that all ViewModels are just "normal pages" - so in iOS/MonoTouch that means UIViewControllers presented using a UINavigationController.

To move away from this premise - towards tabbed displays, modal displays, split controllers, popups, etc - then you can adjust the Presenter logic within your MonoTouch app.

The presenter's job is to implement:

public interface IMvxTouchViewPresenter
{
    void Show(MvxShowViewModelRequest view);
    void Close(IMvxViewModel viewModel);
    void CloseModalViewController();
    void ClearBackStack();
    bool PresentModalViewController(UIViewController controller, bool animated);
    void NativeModalViewControllerDisappearedOnItsOwn();
}

The presenter used for your app is selected in AppDelegate construction - e.g. see how the TwitterSearch builds different presenters for iPhone and iPad.


Fortunately, for simple Modal support, one of the standard presenters available is MvxModalSupportTouchViewPresenter.cs

This presenter looks to see if the view being presented has the IMvxModalTouchView marker interface - it tests view is IMvxModalTouchView. If this interface is present, then it uses modal presentation for the view instead of "normal navigation".

To use this, change your AppDelegate code to something:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        window = new UIWindow(UIScreen.MainScreen.Bounds);

        // initialize app for single screen iPhone display
        var presenter = new MvxModalSupportTouchViewPresenter(this, window);
        var setup = new Setup(this, presenter);
        setup.Initialize();

        // start the app
        var start = this.GetService<IMvxStartNavigation>();
        start.Start();

        window.MakeKeyAndVisible();

        return true;
    } 

Then add the marker interface to your modal View(s):

 public class MyView : MvxBindingTouchViewController<MyViewModel>, IMvxModalTouchView
 {
      // ....
 }


来源:https://stackoverflow.com/questions/10512853/how-do-i-specify-a-view-to-be-pushed-as-modal-in-mvvmcross

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!