8

I encountered a problem when pushing a DialogViewController to my apps global UINavigationController, that it would lose the back buttons.

I was able to boil it down to this simple example:

var nav = new UINavigationController();
window.RootViewController = nav;

nav.PushViewController(new UIViewController() { Title = "#1"}, true);
nav.PushViewController(new DialogViewController(new RootElement("#2")), true);
nav.PushViewController(new UIViewController() { Title = "#3"}, true);

You can get from #3 to #2, but not from #2 to #1.

Am I doing something wrong with the DialogViewController? I though they could work as a drop-in replacement for UIViewController.

poupou
  • 43,413
  • 6
  • 77
  • 174
Timm
  • 2,652
  • 2
  • 25
  • 34

1 Answers1

12

Simply use:

nav.PushViewController(new DialogViewController(new RootElement("#2"), true), true);

i.e. extra true for the DialogViewControler constructor.

poupou
  • 43,413
  • 6
  • 77
  • 174
  • That was tricky. But I assume there are good reasons behind straying away from the default behavior of UIViewController. – Timm Feb 21 '12 at 09:11
  • This has been stumping me for a while. I would love to know how you found that out... – Christian Payne Oct 12 '12 at 06:42
  • 1
    @ChristianPayne I don't exactly recall how I found that out - but it was likely be reading the MT.D's source code, which is available on https://github.com/migueldeicaza/MonoTouch.Dialog – poupou Oct 12 '12 at 12:44