mvvmcrossmonotouch.dialog

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.

Two things to make clear

  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

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.

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);

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);

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


Solution

  • 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).

    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);
            }
    

    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