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

问题描述

支持将要制作稳定流的 iOS 故事板的 XS 集成,我希望能够将此功能与 MVMCross 结合使用.

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.

从根本上说,它看起来有点像它不应该工作,因为故事板指示视图项目中的导航层次结构,而不是像 MVMCross 这样的视图模型项目.

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.

有谁知道这可能是如何实现的?

Does anyone know how this might be achieved?

干杯,特里斯坦

推荐答案

至少发布了一个示例来展示 Storyboards 的使用 - 命名相当奇怪的 eh - https://github.com/slodge/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 数据绑定添加到主要由故事板驱动的应用程序中.

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 从故事板加载 ViewControllers.

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 期间创建您的 MyContainer -

  • create your MyContainer during Setup -

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

  • 那应该就可以了...

  • that should just then work...

    这篇关于Xamarin.iOS 故事板的 MVMCross 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-19 18:17