From 637023d45a553c117f6a5bb6d84de0bb01ed87c6 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 24 Apr 2012 13:11:41 +0200 Subject: [PATCH 1/2] Make DVC work harder to find the UINavigationController to use. This makes DVC work correctly in scenarios when it is nested deep in the hierarchy below a top-level navigation controller. {Activate,Deactivate}Controller made virtual to allow for easier customization. --- MonoTouch.Dialog/DialogViewController.cs | 27 +++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/MonoTouch.Dialog/DialogViewController.cs b/MonoTouch.Dialog/DialogViewController.cs index fe6c8604..76539041 100644 --- a/MonoTouch.Dialog/DialogViewController.cs +++ b/MonoTouch.Dialog/DialogViewController.cs @@ -458,13 +458,11 @@ public override float GetHeightForRow (UITableView tableView, MonoTouch.Foundati /// will push the result. Otherwise it will show it as a modal /// dialog /// - public void ActivateController (UIViewController controller) + public virtual void ActivateController (UIViewController controller) { dirty = true; - var parent = ParentViewController; - var nav = parent as UINavigationController; - + UINavigationController nav = FindNavigationController (); // We can not push a nav controller into a nav controller if (nav != null && !(controller is UINavigationController)) nav.PushViewController (controller, true); @@ -476,17 +474,30 @@ public void ActivateController (UIViewController controller) /// Dismisses the view controller. It either pops or dismisses /// based on the kind of container we are hosted in. /// - public void DeactivateController (bool animated) + public virtual void DeactivateController (bool animated) { - var parent = ParentViewController; - var nav = parent as UINavigationController; - + UINavigationController nav = FindNavigationController (); if (nav != null) nav.PopViewControllerAnimated (animated); else DismissModalViewControllerAnimated (animated); } + protected virtual UINavigationController FindNavigationController () + { + if (NavigationController != null) + return NavigationController; + + UIViewController vc = ParentViewController; + while (vc != null) { + if (vc is UINavigationController) + return vc as UINavigationController; + vc = vc.ParentViewController; + } + + return null; + } + void SetupSearch () { if (enableSearch){ From a326eb235dfe7b25642d9cd39a60c06b5d7de031 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 24 Apr 2012 22:26:21 +0200 Subject: [PATCH 2/2] Look for the parent navigation controller before using NavigationController --- MonoTouch.Dialog/DialogViewController.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MonoTouch.Dialog/DialogViewController.cs b/MonoTouch.Dialog/DialogViewController.cs index 76539041..90cea1c2 100644 --- a/MonoTouch.Dialog/DialogViewController.cs +++ b/MonoTouch.Dialog/DialogViewController.cs @@ -485,15 +485,14 @@ public virtual void DeactivateController (bool animated) protected virtual UINavigationController FindNavigationController () { - if (NavigationController != null) - return NavigationController; - UIViewController vc = ParentViewController; while (vc != null) { if (vc is UINavigationController) return vc as UINavigationController; vc = vc.ParentViewController; } + if (NavigationController != null) + return NavigationController; return null; }