• <i id='7QXpj'><tr id='7QXpj'><dt id='7QXpj'><q id='7QXpj'><span id='7QXpj'><b id='7QXpj'><form id='7QXpj'><ins id='7QXpj'></ins><ul id='7QXpj'></ul><sub id='7QXpj'></sub></form><legend id='7QXpj'></legend><bdo id='7QXpj'><pre id='7QXpj'><center id='7QXpj'></center></pre></bdo></b><th id='7QXpj'></th></span></q></dt></tr></i><div id='7QXpj'><tfoot id='7QXpj'></tfoot><dl id='7QXpj'><fieldset id='7QXpj'></fieldset></dl></div>

      <small id='7QXpj'></small><noframes id='7QXpj'>

      <legend id='7QXpj'><style id='7QXpj'><dir id='7QXpj'><q id='7QXpj'></q></dir></style></legend>
      • <bdo id='7QXpj'></bdo><ul id='7QXpj'></ul>
      1. <tfoot id='7QXpj'></tfoot>

        向 UINavigationController 中的所有视图控制器添加相同的按钮

        Adding same button to all view controllers in UINavigationController(向 UINavigationController 中的所有视图控制器添加相同的按钮)

          <tbody id='HgoaV'></tbody>
          <i id='HgoaV'><tr id='HgoaV'><dt id='HgoaV'><q id='HgoaV'><span id='HgoaV'><b id='HgoaV'><form id='HgoaV'><ins id='HgoaV'></ins><ul id='HgoaV'></ul><sub id='HgoaV'></sub></form><legend id='HgoaV'></legend><bdo id='HgoaV'><pre id='HgoaV'><center id='HgoaV'></center></pre></bdo></b><th id='HgoaV'></th></span></q></dt></tr></i><div id='HgoaV'><tfoot id='HgoaV'></tfoot><dl id='HgoaV'><fieldset id='HgoaV'></fieldset></dl></div>
          • <bdo id='HgoaV'></bdo><ul id='HgoaV'></ul>

            <small id='HgoaV'></small><noframes id='HgoaV'>

            • <legend id='HgoaV'><style id='HgoaV'><dir id='HgoaV'><q id='HgoaV'></q></dir></style></legend>

                <tfoot id='HgoaV'></tfoot>
                  本文介绍了向 UINavigationController 中的所有视图控制器添加相同的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 UINavigationController(像向导页面一样使用),我以编程方式创建,我需要显示一个取消"按钮来取消任何 UIViewController 中的进程.

                  I have a UINavigationController (to use like a wizard page) which I create programmatically and I need to display a "Cancel" button to cancel the process in any UIViewController.

                  创建UINavigationController:

                  FirstVC *firstVC = [[[FirstVC alloc] initWithNibName:@"FirstPage" bundle:nil] autorelease];
                  firstVC.delegate = self;
                  
                  navigationController = [[UINavigationController alloc] initWithRootViewController:firstVC];
                  [self.view addSubview:navigationController.view];
                  

                  添加取消按钮:

                  UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelRequestNewLeave:)];
                  navigationController.topViewController.navigationItem.rightBarButtonItem = cancelButton;
                  [cancelButton release];
                  

                  但是当我将第二个页面推送到 UINavigationController 时,UINavigationBar 上没有显示取消按钮.如果我回到第一页,取消按钮就在那里.因此,显然该按钮仅针对第一个视图添加.我相信这是因为我没有继承 UINavigationController,因为我需要在子视图中使用它.但我不知道如何在以编程方式创建的 UINavigationController 中设置 rightBarButtonItem.

                  But when I push a second page to UINavigationController the cancel button is not shown on the UINavigationBar. If I go back to first page, the cancel button is there. So, apparently the button is added only for the first view. I believe this is because I'm not subclassing UINavigationController, because I need to use it in a subview. But I don't know how to set the rightBarButtonItem in a UINavigationController which is created programmatically.

                  navigationController.topViewController.navigationItem.rightBarButtonItem = cancelButton;
                  

                  有人可以解释一下吗?

                  提前致谢.

                  推荐答案

                  导航项是每个视图控制器.导航栏从当前正在构建其视图的视图控制器的导航项中绘制其内容,该视图对应于导航控制器堆栈顶部的视图控制器.

                  The navigation item is per view controller. The navigation bar draws its contents from the navigation item of the view controller whose view it's currently framing, which corresponds to the view controller at the top of the navigation controller's stack.

                  您基本上需要每个视图控制器在其导航项中粘贴一个取消按钮.您可以执行以下任何操作:

                  You basically need each view controller to stick a cancel button in its navigation item. You can do any of the following:

                  • 将代码复制粘贴到所有相关的视图控制器中.
                  • 将代码移动到实用函数或类中并调用它.
                  • 为所有相关视图控制器创建一个通用超类,以处理为其子类设置取消按钮.

                  这篇关于向 UINavigationController 中的所有视图控制器添加相同的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  UINavigationController inside a UITabBarController inside a UISplitViewController presented modally on iPhone(UISplitViewController 内的 UITabBarController 内的 UINavigationController 以模态方式呈现在 iPhone 上) - IT屋-程序员软件开发技术分
                  ViewController in UINavigationController orientation change(UINavigationController 中的 ViewController 方向更改)
                  Custom back button in UINavigationController(UINavigationController 中的自定义后退按钮)
                  How to add a navigation controller programmatically in code but not as initial view controller(如何在代码中以编程方式添加导航控制器,但不作为初始视图控制器)
                  How to get the previous viewcontroller that pushed my current view(如何获取推送我当前视图的上一个视图控制器)
                  The correct way to set a light status bar text color in iOS 7 based on different ViewControllers(iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法)

                  1. <i id='mjiwt'><tr id='mjiwt'><dt id='mjiwt'><q id='mjiwt'><span id='mjiwt'><b id='mjiwt'><form id='mjiwt'><ins id='mjiwt'></ins><ul id='mjiwt'></ul><sub id='mjiwt'></sub></form><legend id='mjiwt'></legend><bdo id='mjiwt'><pre id='mjiwt'><center id='mjiwt'></center></pre></bdo></b><th id='mjiwt'></th></span></q></dt></tr></i><div id='mjiwt'><tfoot id='mjiwt'></tfoot><dl id='mjiwt'><fieldset id='mjiwt'></fieldset></dl></div>

                    <small id='mjiwt'></small><noframes id='mjiwt'>

                      <bdo id='mjiwt'></bdo><ul id='mjiwt'></ul>
                        <tfoot id='mjiwt'></tfoot>

                          <legend id='mjiwt'><style id='mjiwt'><dir id='mjiwt'><q id='mjiwt'></q></dir></style></legend>
                            <tbody id='mjiwt'></tbody>