简体   繁体   English

嵌套的Monotouch对话框RootElement视图中缺少“后退”按钮

[英]Back Button missing from nested Monotouch Dialog RootElement Views

I have two levels of nested RootElements and at neither level is there a Back Button. 我有两个嵌套的RootElements层次,在这两个层次上都没有Back按钮。

Two things to make clear 有两件事要弄清楚

  1. Yes, I am overriding the DialogViewController and setting "pushing" to True 是的,我要重写DialogViewController并将“ pushing”设置为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 我加入DialogViewController的观点在我MvxViewController一个子视图 ,而不是让使用DialogViewController作为我的主控制器

I have a number of SubViews in my ViewController including a UITableView and a custom UIView. 我的ViewController中有许多SubView,包括一个UITableView和一个自定义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. 我想使用MT D为我提供的带有嵌套RootElements的便捷控制器嵌套,因此我将DialogViewController.View作为SubView插入。

I create the RootElements and Sections longhand 我直接创建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);

Then I pull the View up into my main ViewController like this 然后我将View像这样拉到我的主ViewController中

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

This display the Elements as expected and I can drill down through each RootElement. 这将按预期显示元素,我可以深入浏览每个RootElement。 However none of the Views ever have a Back Button and I cannot see why 但是,所有视图都没有后退按钮,我看不到为什么

The reason for this was because of the way we are using the DialogViewController's View. 这样做的原因是因为我们使用DialogViewController的View的方式。 The code to get a UINavigationController to push a ViewController onto looks at its ParentViewController ( as you can see here ). 获取UINavigationController并将ViewController推送到其上的代码将查看其ParentViewController( 如您在此处看到的 )。

However as mentioned in the question we are lifting the DialogViewController's View up into our ViewController which is abnormal use. 但是,正如问题中提到的,我们将DialogViewController的View提升到我们的ViewController中,这是异常使用。 Below is the code in Monotouch Dialog (MT D). 下面是Monotouch对话框(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 检查为nav的代码不为null,总是会发现它为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);
        }

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 我们在MVVMCross中使用MT D的Fork,这使ActivateController虚拟,因此我们将其覆盖,并将查找UINavigationController的代码更改为

 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 这会检查父母,如果这不好,它会查看父母的父母

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM