问题描述
我有一个 UIButton
,当按下它时,会弹出一个新视图,用户可以在其中更改一些设置.当视图被关闭时,我想更新 UIButton
的标题/文本以反映新状态.我在打电话:
I have a UIButton
, that when pressed, brings up a new view where the user can change some settings. When the view is dismissed, I'd like to update the title/text of the UIButton
to reflect the new state. I'm calling:
[myButton setTitle: @"myTitle" forState: UIControlStateNormal];
[myButton setTitle: @"myTitle" forState: UIControlStateApplication];
[myButton setTitle: @"myTitle" forState: UIControlStateHighlighted];
[myButton setTitle: @"myTitle" forState: UIControlStateReserved];
[myButton setTitle: @"myTitle" forState: UIControlStateSelected];
[myButton setTitle: @"myTitle" forState: UIControlStateDisabled];
但它似乎永远不会改变 IB 中指定的原始文本/标题.
But it never seems to change from the original text/title as specified in IB.
推荐答案
你有没有在你的视图控制器类中将按钮指定为 IBOutlet,并且它在 Interface Builder 中作为一个插座正确连接(从新的引用插座 ctrl 拖动文件所有者并选择您的 UIButton 对象)?当我看到这些症状时,这通常是我遇到的问题.
Do you have the button specified as an IBOutlet in your view controller class, and is it connected properly as an outlet in Interface Builder (ctrl drag from new referencing outlet to file owner and select your UIButton object)? That's usually the problem I have when I see these symptoms.
虽然这里不是这种情况,但如果您为按钮设置属性标题,然后您尝试更改标题而不是属性标题,也会发生类似的情况.
While it's not the case here, something like this can also happen if you set an attributed title to the button, then you try to change the title and not the attributed title.
这篇关于是否可以以编程方式更新 UIButton 标题/文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!