【问题标题】:Monotouch.Dialog: After selection in a RadioElement table, how to update a dependent table?Monotouch.Dialog:在 RadioElement 表中选择后,如何更新依赖表?
【发布时间】:2012-05-29 15:48:51
【问题描述】:

我正在使用 Monotouch.Dialog 开发一个单位转换器,我的主窗口如下所示:

当我点击 Quantity 元素,选择一个新的 Quantity 并返回主窗口时,我想使用与所选数量相关的单位表来更新 Unit 元素。

我最初的想法是在完成数量选择后调用的事件处理程序中更新单位。但是,当我从数量选择返回时,我无法在 MT.D API 中找到触发的事件。是否有这样的事件我可以采取行动,或者是否有其他方法可以进行单元更新?

从示意图上看,我的 AppDelegate.FinishedLaunching 方法现在看起来像这样:

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
  _window = new UIWindow (UIScreen.MainScreen.Bounds);

  _quantityGroup = new RadioGroup("Qty", 0);
  _fromUnitGroup = new RadioGroup("FromU", 0);
  _toUnitGroup = new RadioGroup("ToU", 0);

  var quantityElem = new RootElement("Quantity", _quantityGroup) { 
      new Section() { new RadioElement("AbsorbedDose", "Qty") as Element, ... }};

  var fromUnitElem = new RootElement("Unit", _fromUnitGroup) { new Section() };
  var toUnitElem = new RootElement("Unit", _toUnitGroup) { new Section() }

  _rootElement = new RootElement ("Unit Converter")
  {
    new Section() { quantityElem }, 
    new Section("From") { new EntryElement(...), fromUnitElem },
    new Section("To") { new EntryElement(...), toUnitElem }
  };

  _rootVC = new DialogViewController(_rootElement);
  _nav = new UINavigationController(_rootVC);

  _window.RootViewController = _nav;
  _window.MakeKeyAndVisible();

  return true;
}

【问题讨论】:

  • 看到这个问题 - stackoverflow.com/questions/8302306/…。如果您需要,我在某处有一个更完整的示例。
  • 太好了,非常感谢您的帮助,杰森!在发布我的问题之前,我搜索了一个 SO 答案,但我没有看到那个答案。正如该答案中的 cmets 所指出的,这将是 MT.D 的一个很好的补充。

标签: c# xamarin.ios monotouch.dialog


【解决方案1】:

正如 Jason 在上述评论中所指出的,此问题之前已在 SO here 上解决。

解决方案是扩展RadioElement 类,其中继承类包含OnSelected 事件,并且RadioElement.Selected 方法被调用OnSelected 事件处理程序的方法覆盖。

【讨论】:

  • 还有其他人认为应该有更好的方法来做到这一点吗?我现在不知道...但是,我正在继续搜索
猜你喜欢
  • 2014-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多