4

我尝试了很多方法,但都没有成功。如何在NavigationController上启用/添加BackButton?

这样我可以创建一个新的UIBarButtonItem和它的作品,问题是,它dosent锁像后退按钮/ 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); 

     } 

回答

10

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

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

    } 
} 
+0

谢谢你,它完美的作品! RootElement是进入DVC的项目的顶级容器。 – MemoDreamer 2012-02-16 09:24:15

+0

这很完美! – BRogers 2013-02-11 23:05:06

1

你能不能给一些背景这个好吗?这个ViewController如何被添加到NavigationController?

如果使用PushViewController方法(如下),然后返回按钮将被自动添加。

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

我使用PushViewController方法,以便到达我的视图。 我还可以提到第一个Controller是Monotouch.Dialog中的DialogViewController。 – MemoDreamer 2012-02-15 14:16:54

+0

我很想看看你的代码是如何创建vc并将其推送到导航控制器上的,因为后退按钮一定是为你处理的。 – Blounty 2012-02-15 14:29:03

相关问题