<bdo id='ONifT'></bdo><ul id='ONifT'></ul>

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

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

        为 UINavigationController 制作自定义后退按钮

        时间:2023-06-12

          <legend id='jNeB2'><style id='jNeB2'><dir id='jNeB2'><q id='jNeB2'></q></dir></style></legend>
        1. <small id='jNeB2'></small><noframes id='jNeB2'>

                <tbody id='jNeB2'></tbody>

                <tfoot id='jNeB2'></tfoot>
              • <i id='jNeB2'><tr id='jNeB2'><dt id='jNeB2'><q id='jNeB2'><span id='jNeB2'><b id='jNeB2'><form id='jNeB2'><ins id='jNeB2'></ins><ul id='jNeB2'></ul><sub id='jNeB2'></sub></form><legend id='jNeB2'></legend><bdo id='jNeB2'><pre id='jNeB2'><center id='jNeB2'></center></pre></bdo></b><th id='jNeB2'></th></span></q></dt></tr></i><div id='jNeB2'><tfoot id='jNeB2'></tfoot><dl id='jNeB2'><fieldset id='jNeB2'></fieldset></dl></div>
                  <bdo id='jNeB2'></bdo><ul id='jNeB2'></ul>
                • 本文介绍了为 UINavigationController 制作自定义后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在为 iOS 4.2+ 开发一个应用程序.我将我的 UINavigationController 子类化以插入两个 UIImageView 并使导航栏看起来是自定义的.一切都很好,但我有一个小问题.我创建了自定义 UIBarButtonItem 并在我的视图控制器中将它们放入:

                  I'm developping an app for iOS 4.2+. I subclassed my UINavigationController to insert two UIImageView and make the navigation bar look custom. Everything is working great but I have a little problem. I created custom UIBarButtonItem and inside my view controllers i put them with :

                  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
                  

                  它也可以工作,但问题是要完成这项工作,我需要从以下位置调用它:

                  It works too but the problem is that to make this work I need to call it from:

                   - (void)viewDidAppear:(BOOL)animated ;
                  

                  所以它只出现在动画之后,我可以在自定义按钮替换它之前 1 秒看到非自定义按钮.

                  So it only appears after the animation and I can see the non customized button 1 second before the customized one replace it.

                  (我尝试使用 viewWillAppear 但导航栏中没有附加任何内容)

                  (I tried with viewWillAppear but then nothing append in navigationbar)

                  我想知道您是否有可以解决此问题的解决方案.

                  I would like to know if you have a solution that could correct this problem.

                  PS:我从不使用 IB,一切都是以编程方式制作的.

                  PS: I never use IB, everything is made programmatically.

                  感谢法国!

                  编辑 1:这是 viewWillAppear 没有显示任何内容的代码:

                  EDIT 1: here is the code that didn't show anything for viewWillAppear:

                  - (void)viewWillAppear:(BOOL)animated  {
                      [self setTitle:@"Jeu"];
                  
                      //Bouton testflight
                      TIFButton *testFeedbackButton = [[TIFButton alloc]init];
                      [testFeedbackButton setTitle: @"Envoyer un Feedback" forState:UIControlStateNormal];
                      [testFeedbackButton addTarget:self action:@selector(launchFeedback) forControlEvents:UIControlEventTouchUpInside];
                  
                      UIBarButtonItem *testFeedback = [[UIBarButtonItem alloc] initWithCustomView:testFeedbackButton];
                  
                      self.navigationItem.rightBarButtonItem = testFeedback;  
                  
                      TIFBackButton *backButton = [[TIFBackButton alloc]init];
                      [backButton setTitle: @"Retour" forState:UIControlStateNormal];
                      [backButton addTarget:self action:@selector(popToPrecedentViewController) forControlEvents:UIControlEventTouchUpInside];
                  
                      self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
                  }
                  

                  推荐答案

                  假设您有两个 ViewController,A 和 B,当 A 位于最顶层时,您将 B 压入堆栈,并且您想要自定义返回按钮当 B 在顶部时显示.

                  Let's say you have two ViewControllers, A and B, you're pushing B onto the stack when A is topmost, and you want to customize the back button that shows up when B is on top.

                  通常,这样做的方法是设置 ViewController AnavigationItem.backBarButtonItem.

                  Typically, the way to do this is to set ViewController A's navigationItem.backBarButtonItem.

                  相反,您所做的是通过设置其 navigationItem.leftBarButtonItem 在导航栏左侧为 ViewController B 提供一个自定义按钮.

                  Instead, what you're doing is to give ViewController B a custom button on the left side of the navbar by setting its navigationItem.leftBarButtonItem.

                  您已经很好地实现了该方法,除了即使您不设置 ViewController AnavigationItem.backBarButtonItem,默认情况下您仍然会获得默认返回按钮.因此,该按钮可能会显示在您的自定义后退按钮之上.

                  You've implemented that approach fine, except that even if you don't set ViewController A's navigationItem.backBarButtonItem, by default you still get a default back button as well. So that button is probably showing up on top of your custom back button.

                  如果你设置 ViewController B 的 navigationItem.hidesBackButton = YES 那么你应该没有任何问题.

                  If you set ViewController B's navigationItem.hidesBackButton = YES then you shouldn't have any problem.

                  将来,当您实现自定义后退按钮时,您应该通过设置 navigationItem.backBarButtonItem 而不是 navigationItem.leftBarButtonItem 来实现.您必须进行的一项调整是,使用这种方法,例如,您将使用 ViewController AnavigationItem 更改 ViewController <时显示的后退按钮strong>B 在顶部.

                  And in the future, when you implement custom back buttons, you should do it by setting navigationItem.backBarButtonItem instead of navigationItem.leftBarButtonItem. The one adjustment you'll have to make is that with this approach, for example you would use ViewController A's navigationItem to change the back button that shows up when ViewController B is on top.

                  这篇关于为 UINavigationController 制作自定义后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:导航栏标题和后退按钮名称相同吗? 下一篇:在 UINavigationController 中推送另一个视图?

                  相关文章

                  <legend id='4sWPC'><style id='4sWPC'><dir id='4sWPC'><q id='4sWPC'></q></dir></style></legend>

                  <small id='4sWPC'></small><noframes id='4sWPC'>

                    <bdo id='4sWPC'></bdo><ul id='4sWPC'></ul>

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

                  1. <tfoot id='4sWPC'></tfoot>