gpt4 book ai didi

ios - .xib 中的 UIButton 标题覆盖编程标题更改

转载 作者:行者123 更新时间:2023-12-01 17:54:28 28 4
gpt4 key购买 nike

我正在编写一个应用程序,它加载具有多个按钮的 View (以 .xib 设计)。加载 View 时,我以编程方式设置按钮标题。然后我将 View 添加为 subview 。一瞬间,我看到以编程方式设置的标题出现,然后它们变为 .xib 中的原型(prototype)标题。

这是代码:

self.cellPhoneButton.titleLabel.text = person.cellPhone;
self.homePhoneButton.titleLabel.text = person.homePhone;

// Do other stuff with the view

[self.peopleView addSubview:self.personView];

为什么按钮的标题会恢复为默认内容,为什么页面的其他组件(标签、导航栏标题等)没有发生这种情况?

编辑:

我也尝试了这段代码但没有成功:
[self.cellPhoneButton setTitle:person.cellPhone forState:UIControlStateNormal|UIControlStateSelected];
[self.homePhoneButton setTitle:person.homePhone forState:UIControlStateNormal|UIControlStateSelected];

// Do other stuff with the view

[self.peopleView addSubview:self.personView];

最佳答案

您应该使用 [self.homePhoneButton setTitle: forState:];设置UIButton的方法的头衔。你的情况应该是 UIControlStateNormal这意味着如果您没有明确指定其他状态,则控制状态将适用于所有状态。如果您将 Normal 与其他人结合使用,则 Normal 将被覆盖。

关于ios - .xib 中的 UIButton 标题覆盖编程标题更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20648891/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com