在MonoTouch上将第三方控制器与MVVMCross集成 [英] Integrating third party controller with MVVMCross on MonoTouch
问题描述
我想使用已经从UIViewController继承的第三方视图控制器( https://bitbucket.org/thedillonb/monotouch.slideoutnavigation/src/f4e51488598b/MonoTouch.SlideoutNavigation?at=master ),如何将其与MVVMCross集成?
I want to use a third party view controller that already inherits from UIViewController (https://bitbucket.org/thedillonb/monotouch.slideoutnavigation/src/f4e51488598b/MonoTouch.SlideoutNavigation?at=master), how would I integrate that with MVVMCross?
我可以直接获取源代码并将其更改为从MvxViewController继承,但是猜测我将与其他库一起使用.
I could just take the source and change it to inherit from MvxViewController, but guessing I will run into this with other libraries.
我需要实现MvxViewController的所有接口吗? IMvxTouchView? IMvxEventSourceViewController?
Do I need to implement all the interfaces MvxViewController does? IMvxTouchView? IMvxEventSourceViewController?
推荐答案
在这种情况下,您实际上不需要进行任何数据绑定,因此您可以使用自定义演示者-例如请参阅@Blounty的答案,或查看此项目演示- https://github.com/fcaico/MvxSlidingPanels.Touch
For this particular case, where you don't actually want to do any data-binding so you can just use a custom presenter - e.g. see @Blounty's answer, or see this project demo - https://github.com/fcaico/MvxSlidingPanels.Touch
如果您确实需要转换第三方ViewController
基类,以便它们支持数据绑定,那么最简单的方法就是您所猜测的:
If you ever do need to convert third party ViewController
base classes so that they support data-binding, then the easiest way is exactly what you guessed:
-
从
- 继承它们以提供
EventSource
-ViewController - 从
EventSource
-ViewController继承以添加Mvx BindingContext
- inherit from them to provide an
EventSource
-ViewController - inherit from the
EventSource
-ViewController to add the Mvx BindingContext
此技术正是MvvmCross
本身如何扩展UIViewController
,UITableViewController
,UITabBarController
等以提供数据绑定的方式.
This technique is exactly how MvvmCross
itself extends each of UIViewController
, UITableViewController
, UITabBarController
, etc in order to provide data-binding.
例如,请参阅:
- 扩展UIViewController以提供事件源- MvxViewController.cs
- extending UIViewController to provide an eventsource - MvxEventSourceViewController.cs
- extending the event source ViewController to provide a binding context - MvxViewController.cs
请注意,由于C#没有任何多重继承或任何真正的Mixin支持,因此对ViewControllers的改编确实涉及一些剪切和粘贴,但是我们已尝试通过使用事件挂钩和扩展来将其最小化.方法.
Note that because C# doesn't have any Multiple-Inhertiance or any true Mixin support, this adaption of ViewControllers does involve a little cut-and-paste, but we have tried to minimise this through the use of event hooks and extension methods.
如果有帮助,可以在集成Google中讨论该MvvmCross早期版本的iOS技术带有MVVMCross的移动分析(显然,这已经过时了-但一般原理仍然保持不变-我们通过继承调整了现有的viewcontroller)
If it helps, this iOS technique for a previous MvvmCross version was discussed in Integrating Google Mobile Analytics with MVVMCross (obviously this is out of date now - but the general principles kind of remain the same - we adapt an existing viewcontroller via inheritance)
在Android中,Activity基类也遵循类似的过程-请参见 ActionBarSherlock与最新的MVVMCross
In Android, a similar process is also followed for Activity base classes - see ActionBarSherlock with latest MVVMCross
这篇关于在MonoTouch上将第三方控制器与MVVMCross集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!