是否可以通过编程方式更新UIButton标题/文本? [英] is it possible to update UIButton title/text programmatically?

查看:111
本文介绍了是否可以通过编程方式更新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 drag从新的引用插座到文件所有者并选择你的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标题/文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆