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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions MonoTouch.Dialog/DialogViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// </summary>
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);
Expand All @@ -476,17 +474,29 @@ public void ActivateController (UIViewController controller)
/// Dismisses the view controller. It either pops or dismisses
/// based on the kind of container we are hosted in.
/// </summary>
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 ()
{
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 ()
{
if (enableSearch){
Expand Down