简体   繁体   English

iOS在当前ViewController中设置BackButton

[英]iOS set BackButton in the current ViewController

How can I change the Back-Button of the currently displayed ViewController? 如何更改当前显示的 ViewController的后退按钮? Configuring the BackButtonItem effects the BackButton of the next ViewController, instead of the currently shown. 配置BackButtonItem会影响下一个ViewController的BackButton,而不是当前显示的BackButton。

eg: I have two ViewControllers VCA and VCB. 例如:我有两个ViewController VCA和VCB。 I navigate from VCA to VCB and want to style the BackButton thats shown on VCB. 我从VCA导航到VCB,并希望设置VCB上显示的BackButton的样式。 I want to hide the title and set custom icons for normal and highlighted state. 我想隐藏标题并为正常和突出显示状态设置自定义图标。

public class VCB : ViewControllerBase
{
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        var btn = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
        // TODO: set the Icon
        NavigationItem.BackBarButtonItem = btn;
    }
}

Do I have to implement my own BackButton and set it as LeftBarButton, or can I achieve this somehow with the standard BackButton . 我是否必须实现自己的BackButton并将其设置为LeftBarButton,还是可以使用标准BackButton某种方式实现呢?

如果BarButtonItem在视图中已经有BarButtonItem ,则应该可以使用this.NavigationItem.BackBarButtonItem并更改其属性。

You can try this in your ViewDidLoad method: 您可以在ViewDidLoad方法中尝试以下方法:

UIBarButtonItem backButton = new UIBarButtonItem("< Back",UIBarButtonItemStyle.Plain, null);
this.NavigationItem.SetLeftBarButtonItem(backButton, false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ios-不向ViewController上的NavigationBar添加backbutton - ios - Not adding backbutton to NavigationBar on ViewController 如何在iOS中的BackButton位置设置LeftBarButton - How to set LeftBarButton at the place of BackButton in ios 如何在iOS中找到当前可见的ViewController - How to find current visible viewController in iOS 在iOS 6中的当前ViewController上更改backBarButtonItem颜色 - Change backBarButtonItem color on current ViewController in iOS 6 iOS:如何在当前上下文中推送ViewController? - iOS: how to push ViewController over current context? iOS uiviewcontroller:如果将rootviewcontroller设置为新的viewcontroller,则viewcontroller会免费 - IOS uiviewcontroller: will the viewcontroller be free if rootviewcontroller is set to a new viewcontroller Xcode设置ViewController身份iOS OpenGL - Xcode set viewcontroller identity iOS OpenGL 在IOS 7中检查当前viewController类是否为ABPersonViewController时出现问题 - Issue when checking if current viewController class is ABPersonViewController in IOS 7 如何通过IOS Swift中的任何后台进程获取当前的viewcontroller - How to get current viewcontroller through any background process in IOS Swift 如何在iOS中的当前ViewController之前找到所有View Controller? - How to find all the view controllers before my current viewcontroller in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM