DialogViewController breaks UINavigationController path
Asked Answered
S

1

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.

Spano answered 20/2, 2012 at 17:34 Comment(0)
A
12

Simply use:

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

i.e. extra true for the DialogViewControler constructor.

Ain answered 20/2, 2012 at 18:7 Comment(3)
That was tricky. But I assume there are good reasons behind straying away from the default behavior of UIViewController.Spano
This has been stumping me for a while. I would love to know how you found that out...Defiant
@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 github.com/migueldeicaza/MonoTouch.DialogAin

© 2022 - 2024 — McMap. All rights reserved.