简体   繁体   中英

MonoTouch.Dialog: Back item in NavigationBar

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

DialogViewController的构造函数有一个名为push的参数,您应该将其设置为true:

new DialogViewController(rootElement, true); // true will show the back button

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.

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

You can also implement by yourself

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

              NavigationController.DismissModalViewControllerAnimated(true);
            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM