Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make finding navigation controller in DVC more flexible #123

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

grendello
Copy link

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
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
Author

Will this version work better?

@gratner
Copy link
Contributor

gratner commented Dec 10, 2012

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
Copy link

tystol commented Feb 14, 2013

@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