如何在 MvvmCross 中指定要作为模态推送的视图? [英] How do I specify a view to be pushed as Modal in MvvmCross?

查看:12
本文介绍了如何在 MvvmCross 中指定要作为模态推送的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 MvvmCross 框架的 MonoTouch 应用程序中有一个视图,我希望显示模态 (NavigationController.PresentModalViewController).

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

推荐答案

MvvmCross 的前提是所有 ViewModel 都只是普通页面"——所以在 iOS/MonoTouch 中,这意味着 UIViewController 使用 UINavigationController 呈现.

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

要摆脱这个前提 - 转向选项卡式显示、模式显示、拆分控制器、弹出窗口等 - 然后您可以在 MonoTouch 应用程序中调整演示器逻辑.

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.

演示者的工作是实现:

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

在 AppDelegate 构造中选择用于您的应用程序的演示者 - 例如了解 TwitterSearch 为 iPhone 和 iPad 构建不同的演示者.

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

幸运的是,对于简单的 Modal 支持,可用的标准演示器之一是 MvxModalSupportTouchViewPresenter.cs

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

此演示者查看所呈现的视图是否具有 IMvxModalTouchView 标记界面 - 它测试 视图是否为 IMvxModalTouchView.如果存在此界面,则它使用视图的模态呈现而不是正常导航".

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".

要使用它,请将您的 AppDelegate 代码更改为:

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
 {
      // ....
 }

这篇关于如何在 MvvmCross 中指定要作为模态推送的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆