Skip to content

Make finding navigation controller in DVC more flexible#123

Open
grendello wants to merge 3 commits into
migueldeicaza:masterfrom
grendello:master
Open

Make finding navigation controller in DVC more flexible#123
grendello wants to merge 3 commits into
migueldeicaza:masterfrom
grendello:master

Conversation

@grendello

Copy link
Copy Markdown

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.

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.
@migueldeicaza

Copy link
Copy Markdown
Owner

This patch changes the behavior for ActivateController, before it did:

var parent = ParentViewController;
var nav = parent as UINavigationController;

Now nav is instead this.NavigationController, which might not be the parent.

@grendello

Copy link
Copy Markdown
Author

Will this version work better?

@gratner

gratner commented Dec 10, 2012

Copy link
Copy Markdown
Contributor

Miguel, one part of grendello's changes allows for DVC to be embedded as a child view (for example in a split screen scenario). I am attaching the specific diff for that section below.

If only these changes will get submitted as a pull, will you merge them in or do you see a problem with this setup?

Thanks!


--- a/MonoTouch.Dialog/DialogViewController.cs
+++ b/MonoTouch.Dialog/DialogViewController.cs
@@ -461,10 +461,9 @@
        public void ActivateController (UIViewController controller)
        {
            dirty = true;
-           
-           var parent = ParentViewController;
-           var nav = parent as UINavigationController;
-           
+
+           var nav = FindNavigationController();
+
            // We can not push a nav controller into a nav controller
            if (nav != null && !(controller is UINavigationController))
                nav.PushViewController (controller, true);
@@ -478,15 +477,29 @@
        /// </summary>
        public void DeactivateController (bool animated)
        {
-           var parent = ParentViewController;
-           var nav = parent as UINavigationController;
-           
+           var nav = FindNavigationController ();
+
            if (nav != null)
                nav.PopViewControllerAnimated (animated);
            else
                DismissModalViewControllerAnimated (animated);
        }

+       protected virtual UINavigationController FindNavigationController ()
+       {
+           UIViewController vc = ParentViewController;
+           while (vc != null) {
+               if (vc is UINavigationController)
+                   return vc as UINavigationController;
+               vc = vc.ParentViewController;
+           }
+           if (NavigationController != null)
+               return NavigationController;
+           
+           return null;
+       }
+
        void SetupSearch ()

@tystol

tystol commented Feb 14, 2013

Copy link
Copy Markdown

@migueldeicaza RE:

This patch changes the behavior for ActivateController, before it did:
var parent = ParentViewController;
var nav = parent as UINavigationController;
Now nav is instead this.NavigationController, which might not be the parent.

I beleive that is the point of the pull request - to look higher than the immediate parent for a nav controller used to navigate.
For example, I have my own container view controller (SegmentedViewController) that puts a UISegmentedControl in the parent nav bar, and allows each segment to map to a child controller. When I use this with a DVC as each child controller, element navigation causes modal style navigation as the parent is the SegmentedViewController. With these changes each DVC will find the grandparent nav controller correctly and navigate to the right nicely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants