MonoTouch.Dialog: Back item in NavigationBar
Asked Answered
D

4

6

I m having a hard time with this issue. My MainWindow.xib, has a NavigationController, the view for which is inherited from another xib.

Now, i push a DialogViewController from the main view, but i cannot see a back button on the second view's navigation bar.

Is there anything specific that i need to set for the DialogViewController when it is being pushed from a UIViewController.

Thanks and Regards Abhishek

Denny answered 19/12, 2011 at 11:10 Comment(0)
L
15

The constructor for DialogViewController has a parameter called pushing which you should set to true:

new DialogViewController(rootElement, true); // true will show the back button
Lymphocytosis answered 21/4, 2012 at 23:16 Comment(1)
BTW, all the "true" parameter does is set NavigationItem.HidesBackButton to false. It does that in the ViewWillAppear method, so if you override that method you can get the back button to show again. That's helpful if you're pushing the DialogViewController via a storyboard.Biller
C
2

Without seeing your code, I'm not sure exactly what's going wrong here. However, from what I know of UINavigationController, the view controller stack starts empty. When you push the first view controller, it gives the navigation controller a view to display, but it has nothing to go 'back' to, so it does not display a back button. If you push a second view, you may get a back button.

Also, be sure that the Title property is set on your child view controllers if you want the back button to reflect the view you will be going back to.

Chinachinaberry answered 20/12, 2011 at 4:0 Comment(0)
C
0

I have a tab bar controller which then hands off to a nav controller (in a storyboard with flyoutnavcontollers too). One of the viewcontrollers from here launches into a dialogviewcontroller for MT.D stuff.

I wanted a lovely pointed/tapered back button from monotouch dialog back to my calling point in the navigation controller.

But launching into MT.D loses the navigation even when im using the current navigation controller for some reason i.e. the button is not displayed and no way to get back. Subsequent mt.d screens give a back button.

Apparently your supposed to pass a true boolean into call to enable back button whilst pushing onto existing stack but this didnt work for me:

this.NavigationController.PushViewController (dv, true);

Dan's above solution didnt work for me. But popping the current dialogviewcontroller whilst at the root MT.D screen helps to get back to my previous position in the original nav controller in the storyboard (or flyoutnav controller).

Not sure if this hack is the correct way but it works.

dv.NavigationItem.RightBarButtonItem = new UIBarButtonItem("Back",UIBarButtonItemStyle.Bordered,delegate(object sender,EventArgs e) 
            {   

                NavigationController.PopViewControllerAnimated(true);
            });

* update

I manged to get a back button by adding the dialogviewcontroller to current viewcontrollers subview:

 dvc = new MyDvcController(this.NavigationController);
 this.View.AddSubview(dvc.TableView);

the corresponding MyDvcController mainly loooks like this:

public partial class MyDvcController : DialogViewController
{
    public MyDvcController (UINavigationController nav): base (UITableViewStyle.Grouped, null)
    {

        navigation = nav;
        Root = new RootElement ("Demos"){
            new Section ("Element API"){
                new StringElement ("iPhone Settings Sample", DemoElementApi),

            }
        };
    }  
}

this allowed the monotouch.dialog to be part of the current navigation controllers stack and achieve automatic back button with the tapered look ..yay

Calumet answered 16/4, 2013 at 3:12 Comment(0)
O
-1

You can also implement by yourself

dialogViewController.NavigationItem.RightBarButtonItem = new UIBarButtonItem("Back",UIBarButtonItemStyle.Bordered,delegate(object sender,EventArgs e) 
            {   

              NavigationController.DismissModalViewControllerAnimated(true);
            });
Oral answered 13/2, 2012 at 18:33 Comment(1)
This creates a button on the right side of the navigation bar. Not the arrowed back button on the left.Laminous

© 2022 - 2024 — McMap. All rights reserved.