MVVM对Xamarin.iOS Storyboard的交叉支持 [英] MVVMCross support for Xamarin.iOS Storyboards

查看:82
本文介绍了MVVM对Xamarin.iOS Storyboard的交叉支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于支持即将制作稳定视频流的iOS故事板的XS集成,我希望能够将此功能与MVVMCross结合使用.

With support for XS integration of iOS storyboards about to make the Stable stream, I would love to be able to use this feature in conjunction with MVVMCross.

从根本上说,它似乎确实不应该工作,因为情节提要指示的是视图项目中的导航层次结构,而不是像MVVMCross这样的视图模型项目.

Fundamentally it does seem a little like it should not work, as with storyboards indicate navigational hierarchy in the view project, rather than a viewmodel project like MVVMCross.

但是,如果有一种方法可以使两者一起工作,那就太棒了.

But it would be awesome if there is a way to make the 2 work together.

有人知道如何实现吗?

特里斯坦干杯

推荐答案

至少发布了一个示例,演示了情节提要的使用-相当奇怪的eh-

There is at least one sample published showing the use of Storyboards - the rather oddly named eh - https://github.com/slodge/eh

此示例的工作人员:

  • letting the Storyboard control the navigation
  • using MvxViewController as a VC base class (in place of UIViewController)
  • manually setting the ViewModel in one case - by setting it directly before calling base.ViewDidLoad() - see https://github.com/slodge/eh/blob/master/storyb/RootViewController.cs#L23
  • manually setting the Request in one case - during the Segue navigation - see https://github.com/slodge/eh/blob/master/storyb/RootViewController.cs#L40

使用这样的方法,可以很容易地将Mvx数据绑定添加到主要由Storyboard驱动的应用程序中.

Using approaches like this it's pretty easy to add Mvx Data-Binding to an application that is primarily driven by the Storyboard.

或者,如果开发人员希望让Mvx ShowViewModel导航系统控制屏幕的流程-但也希望将这些屏幕设计在情节提要中,则可以通过开发普通的MvvmCross应用程序来实现,但可以使用一个自定义的Presenter,可以从情节提要中加载ViewController.

Alternatively, if developers would prefer to let the Mvx ShowViewModel navigation system control the flow of screens - but would also prefer those screens to be designed within a storyboard, then this is possible by developing a normal MvvmCross application, but using a custom Presenter which loads ViewControllers from the storyboard.

在MvvmCross v3.1.1中,您可以在ViewsContainer级别执行此操作:

In v3.1.1 of MvvmCross, you can do this at the ViewsContainer level:

  • override a class MyContainer from MvxTouchViewsContainer.cs
  • override the method protected virtual IMvxTouchView CreateViewOfType(Type viewType, MvxViewModelRequest request) - see https://github.com/MvvmCross/MvvmCross/blob/b8545752f28f4e569efeaa397c3085b0373e4d8b/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTouchViewsContainer.cs#L40
  • in this override, load your Storyboard-based ViewControllers:

 protected override IMvxTouchView CreateViewOfType(Type viewType, MvxViewModelRequest request)
 {
     return (IMvxTouchView)UIStoryboard.FromName("MyStoryBoard", null)
                                       .InstantiateViewController(viewType.Name);
 }

  • Setup-

    protected override IMvxTouchViewsContainer CreateTouchViewsContainer()
    {
        return new MyContainer();
    } 
    

  • 那应该可以正常工作...

  • that should just then work...

    这篇关于MVVM对Xamarin.iOS Storyboard的交叉支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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