【问题标题】:Back Button missing from nested Monotouch Dialog RootElement Views嵌套的 Monotouch 对话框 RootElement 视图中缺少后退按钮
【发布时间】:2015-05-28 10:41:38
【问题描述】:

我有两层嵌套的 RootElement,两层都没有返回按钮。

两件事要弄清楚

  1. 是的,我正在覆盖 DialogViewController 并将“推送”设置为 True
  2. 我将 DialogViewController 的视图添加为 MvxViewController 中的 SubView,而不是使用 DialogViewController 作为我的主控制器

我的 ViewController 中有许多子视图,包括 UITableView 和自定义 UIView。我想使用 MT D 为我提供的嵌套 RootElements 的控制器的方便嵌套,因此我将 DialogViewController.View 作为子视图插入。

我以手写方式创建 RootElements 和 Sections

RootElement filtersListRootElement = new RootElement("Filters");
Section filterTypes = new Section();
RootElement filterRootElement = new RootElement("Filter Options");
RootElement byDateRoot = new RootElement("Date");
RootElement byCategoryRoot = new RootElement("Category");

filterRootElement.Add(new Section());
filterRootElement.Sections.First().Elements.Add(byDateRoot);
filterRootElement.Sections.First().Elements.Add(byCategoryRoot);

byDateRoot.Add(new Section("Some Stuff"));
byDateRoot.Sections.First().Elements.Add(new CheckboxElement("Yesterday"));
byDateRoot.Sections.First().Elements.Add(new CheckboxElement("Last Week"));
byDateRoot.Sections.First().Elements.Add(new CheckboxElement("Last 6 months"));
byDateRoot.Sections.First().Elements.Add(new CheckboxElement("2 years"));

byCategoryRoot.Add(new Section());
byCategoryRoot.Sections.First().Elements.Add(new CheckboxElement("Medications"));
byCategoryRoot.Sections.First().Elements.Add(new CheckboxElement("Lifestyle"));
byCategoryRoot.Sections.First().Elements.Add(new CheckboxElement("Tests"));

filterTypes.Elements.Add(filterRootElement);
filtersListRootElement.Sections.Add(filterTypes);

然后我像这样将 View 拉到我的主 ViewController 中

DialogViewController filtersListDvc =
    new DialogViewController(UITableViewStyle.Plain, filtersListRootElement, true);
this.AddChildViewController(filtersListDvc);
this.View.AddSubview(filtersListDvc.View);
filtersListDvc.DidMoveToParentViewController(this);

这会按预期显示元素,我可以向下钻取每个 RootElement。然而,没有一个视图有后退按钮,我不明白为什么

【问题讨论】:

    标签: mvvmcross monotouch.dialog


    【解决方案1】:

    这是因为我们使用 DialogViewController 的 View 的方式。获取 UINavigationController 以将 ViewController 推送到其上的代码查看其 ParentViewController (as you can see here)。

    但是,正如问题中提到的,我们将 DialogViewController 的 View 提升到我们的 ViewController 中,这是异常使用。以下是 Monotouch Dialog (MT D) 中的代码。检查nav is not null 的代码总是发现它为空,因为在我们的用例中 UINavigationController 是另一个级别

    public void ActivateController (UIViewController controller)
            {
                dirty = true;
    
                var parent = ParentViewController;
                var nav = parent as UINavigationController;
    
                // We can not push a nav controller into a nav controller
                if (nav != null && !(controller is UINavigationController))
                    nav.PushViewController (controller, true);
                else
                    PresentModalViewController (controller, true);
            }
    

    我们在 MVVMCross 中使用了一个 MT D 的 Fork,这使得 ActivateController 是虚拟的,所以我们覆盖它并将查找 UINavigationController 的代码更改为

     this.PushNavigationController = this.PushNavigationController
                                                ?? parent as UINavigationController
                                                ?? parent.ParentViewController as UINavigationController;
    

    这会检查父级,如果不好,它会查看父级的父级

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多