【问题标题】:How to bind button click commands in ReactiveUI for iOS如何在 ReactiveUI for iOS 中绑定按钮单击命令
【发布时间】:2014-05-02 18:34:57
【问题描述】:

我正在尝试为 Xamarin.iOS 项目学习 ReactiveUI,但我一直坚持应该是一项简单的任务。我无法像在我的伴侣 Xamarin.Android 项目中那样将按钮单击绑定到 ReactiveCommand。这是运行良好的 Android 代码:

this.BindCommand (ViewModel, x => x.ClickMe, view => view._button);

这是在 iOS 中使用的相同模式:

this.BindCommand (ViewModel, x => x.ClickMe, view => view.GetForecastButton);

但是,在 iOS 中,我收到以下警告:

“找不到 MonoTouch.UIKit.UIButton 的命令绑定器”

有谁知道我做错了什么?令人惊讶的是,我查看了数十个 ReactiveUI iOS 示例,但仍然没有找到一个在应用程序中甚至只有一个按钮的示例。它们都做一些事情,比如显示绑定属性中的文本或显示 ViewModel 中的集合中的 UITableView。我确信那里有一个更完整的 iOS 示例,如果有人知道,请在您的答案中包含。非常感谢。

【问题讨论】:

    标签: mvvm xamarin reactiveui


    【解决方案1】:

    您所做的一切都是正确的,但我相信您被一个影响 ReactiveUI 的 Xamarin.iOS 错误所控制,其中Type.GetType 不会加载程序集。将此粘贴到您的 AppDelegate 中:

    https://github.com/paulcbetts/starter-mobile/blob/master/Starter-iOS/AppDelegate.cs#L35

            // NB: GrossHackAlertTiem™:
            //
            // Monotouch appears to not load assemblies when you request them 
            // via Type.GetType, unlike every other platform (even 
            // Xamarin.Android). So, we've got to manually do what RxUI and 
            // Akavache would normally do for us
            var r = RxApp.MutableResolver;
            (new ReactiveUI.Cocoa.Registrations()).Register((f,t) => r.Register(f, t));
            (new ReactiveUI.Mobile.Registrations()).Register((f,t) => r.Register(f, t));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      相关资源
      最近更新 更多