嵌套的Monotouch对话框RootElement视图中缺少“后退"按钮 [英] Back Button missing from nested Monotouch Dialog RootElement Views

查看:114
本文介绍了嵌套的Monotouch对话框RootElement视图中缺少“后退"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两层嵌套的RootElement,而在这两个层上都没有一个后退"按钮.

I have two levels of nested RootElements and at neither level is there a Back Button.

有两件事要弄清楚

  1. 是的,我要重写DialogViewController并将"pushing"设置为True
  2. 我将DialogViewController的视图作为 SubView 添加到我的 MvxViewController 中,而不是使用DialogViewController作为我的主控制器
  1. Yes, I am overriding the DialogViewController and setting "pushing" to True
  2. I am adding the DialogViewController's View as a SubView in my MvxViewController rather than having the using the DialogViewController as my main controller

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

I have a number of SubViews in my ViewController including a UITableView and a custom UIView. I want to use the convenient nesting of Controllers that MT D gives me with nested RootElements so I am inserting the DialogViewController.View as a SubView.

我直接创建RootElements和Sections

I create the RootElements and Sections longhand

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中

Then I pull the View up into my main ViewController like this

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

这将按预期显示元素,我可以深入研究每个RootElement.但是,所有视图都没有后退按钮,我看不到为什么

This display the Elements as expected and I can drill down through each RootElement. However none of the Views ever have a Back Button and I cannot see why

推荐答案

之所以如此,是因为我们使用DialogViewController的View的方式.获取UINavigationController并将ViewController推送到其上的代码将查看其ParentViewController(如您所见).

The reason for this was because of the way we are using the DialogViewController's View. The code to get a UINavigationController to push a ViewController onto looks at its ParentViewController (as you can see here).

但是,正如问题中提到的,我们将DialogViewController的View提升到我们的ViewController中,这是异常使用.下面是Monotouch对话框(MT D)中的代码.检查为nav的代码不是null总是会发现它为null,因为在我们的用例中,UINavigationController是另一个上层

However as mentioned in the question we are lifting the DialogViewController's View up into our ViewController which is abnormal use. Below is the code in Monotouch Dialog (MT D). The code that check is nav is not null wasalways finding it to be null as in our use-case the UINavigationController was another level up

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的代码更改为

We are using a Fork of MT D in MVVMCross and that makes ActivateController virtual so we override it and changed the code that looked for a UINavigationController to

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

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

This checks the parent and if that is no good it looks at the parent's Parent

这篇关于嵌套的Monotouch对话框RootElement视图中缺少“后退"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆