C# 如何在NavigationController上启用/添加BackButton?

C# 如何在NavigationController上启用/添加BackButton?,c#,uinavigationcontroller,xamarin.ios,uibarbuttonitem,uinavigationitem,C#,Uinavigationcontroller,Xamarin.ios,Uibarbuttonitem,Uinavigationitem,我试过很多方法,但都没有成功 通过这种方式,我可以创建一个新的UIBarButtonim,它可以工作,问题是它没有像backButton/ArrowBackButton那样锁定: public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); this.Navigatio

我试过很多方法,但都没有成功

通过这种方式,我可以创建一个新的UIBarButtonim,它可以工作,问题是它没有像backButton/ArrowBackButton那样锁定:

            public override void ViewWillAppear (bool animated) 
            { 
               base.ViewWillAppear (animated);  


               this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem  ("Tillbaka", UIBarButtonItemStyle.Plain, delegate(object sender, EventArgs e) { 
               this.NavigationController.PopViewControllerAnimated (true);  
                    }); 

            } 
我尝试过这个,但没有成功:

      public override void ViewWillAppear (bool animated)
     {
        base.ViewWillAppear (animated); 

            this.NavigationItem.SetHidesBackButton(false,true);

         }

你能给我讲讲这件事的来龙去脉吗?如何将此ViewController添加到NavigationController

如果使用PushViewController方法(如下所示),则会自动添加后退按钮

var viewController = new UIViewController();
this.NavigationController.PushViewController(viewController, true);

使用MonoTouch.Dialog,您必须设置一个“按下”标志,以便显示后退按钮。您可以在构造函数中执行此操作,如下所示:

public class MyViewController : DialogViewController
{
    public MyViewController
        : base(new RootElement("foo"), true)
    {

    }
}

我使用PushViewController方法,以便获得我的视图。我还可以提到,第一个控制器是Monotouch.Dialog的DialogViewController。我很想看看你的代码,看看你是如何创建vc并将其推到导航控制器上的,因为后退按钮肯定会为你处理。谢谢你,它工作得很好!RootElement是进入DVC的项目的顶级容器。