是否可以以编程方式更新 UIButton 标题/文本?

is it possible to update UIButton title/text programmatically?(是否可以以编程方式更新 UIButton 标题/文本?)
本文介绍了是否可以以编程方式更新 UIButton 标题/文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 标题/文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)