<legend id='icXVc'><style id='icXVc'><dir id='icXVc'><q id='icXVc'></q></dir></style></legend>
      • <bdo id='icXVc'></bdo><ul id='icXVc'></ul>

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

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

      1. <tfoot id='icXVc'></tfoot>

        UIButton 标题更改为默认值

        时间:2023-07-07
      2. <small id='Ssrei'></small><noframes id='Ssrei'>

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

                1. <legend id='Ssrei'><style id='Ssrei'><dir id='Ssrei'><q id='Ssrei'></q></dir></style></legend>
                    <tbody id='Ssrei'></tbody>
                  本文介绍了UIButton 标题更改为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我觉得这可能是一个愚蠢的问题......但无论如何我有这种奇怪的 UIButton 标题行为.

                  I feel like this is probably a stupid question... but anyway I have this kind of weird UIButton title behavior.

                  按钮已设置并连接到 IB 中的动作和属性(动作是 startButtonPushed,属性是 startButton).在视图控制器内部,我的操作设置如下:

                  The button is set up and connected to both an action and a property in IB (the action is startButtonPushed and the property is startButton). Inside the view controller I have the action set up like this:

                  bool buttonStateStop;
                  
                  - (IBAction)startPushed:(id)sender 
                  {
                      if (buttonStateStop) 
                      {
                          [appD.locationManager stopSavingLocations];
                          startButton.titleLabel.text = @"Start";
                          buttonStateStop = NO;
                      }
                      else 
                      {
                          [appD.locationManager startSavingLocations];
                          startButton.titleLabel.text = @"Stop";
                          buttonStateStop = YES;        
                      }
                  }
                  

                  最初我将 IB 中的默认标题设置为开始",但每当我按下按钮时,它会在几分之一秒内变为停止",然后返回.我花了一段时间试图弄清楚为什么标题总是回到开始".最终,我将 IB 标题更改为xxxxxx",并意识到无论如何,按钮标题更改后,IB 标题都会立即重新声明.

                  Originally I had the default title in IB set to "Start" but whenever I pressed the button it would change to "Stop" for a fraction of a second and then back. I spent a while trying to figure out why the title kept getting set back to "Start". Eventually I changed the IB title to "xxxxxx" and realized that no matter what, the IB title gets reasserted immediately after the title of the button changes.

                  所以问题是:为什么 IB 不断将按钮的标题改回默认值?我以前从未遇到过这种行为.并且(显然)我该如何解决?

                  So the question is: why does IB keep changing the button's title back to default? I've never come across this behavior before. And (obviously) how can I fix it?

                  额外信息:对按钮的唯一引用是 @property@synthesize 和上面代码中的语句.视图位于导航控制器内部.

                  Extra info: the only references to the button are the @property, @synthesize, and the statements in the code above. The view is inside of a navigation controller.

                  推荐答案

                  你需要使用 setTitle:forState: 方法,而不是设置 titleLabel.text 属性:

                  You need to use setTitle:forState: method instead of setting the titleLabel.text property:

                  [startButton setTitle:@"Start" forState:UIControlStateNormal];
                  // Normal and highlighted titles do not need to be the same
                  [startButton setTitle:@"Start!" forState:UIControlStateHighlighted];
                  

                  现在发生的情况是,您在标签中设置了代表当前状态视图的标题,但是一旦状态从 push 变为 normal,按钮会将标签重置为新状态的标题(即您在 IB 中设置的文本).

                  What happens now is that you set the title in the label that represents the view of the current state, but once the state changes from pushed to normal, the button resets the label back to the title for the new state (which is the text that you set in the IB).

                  这篇关于UIButton 标题更改为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何为 UIControl/UIButton 动画从一种状态到另一种状态的过渡? 下一篇:如何在 Swift 中为状态设置属性标题颜色

                  相关文章

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

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

                      <tfoot id='TlC4q'></tfoot>
                      <legend id='TlC4q'><style id='TlC4q'><dir id='TlC4q'><q id='TlC4q'></q></dir></style></legend>

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