iOS UIButton 标题在 UITableViewCell 中不断恢复
iOS UIButton title keeps reverting in UITableViewCell
我正在尝试设置一个相当简单的 Storyboard/Interface 构建器应用程序 UITableViewController
,带有两个原型单元格。
第一个原型单元显示主UILabel
上的信息,第二个原型单元包含一个UIButton
。我已将按钮的touchUpInside
操作连接到一些我想执行内容并修改按钮标题的代码:
- (IBAction)startButtonTouchUpInside:(UIButton *)sender {
[self doSomeStuff];
sender.titleLabel.text = @"Clicked";
}
然而,当我测试应用程序并单击 UIButton
时,UIButtons
标题会更改几分之一秒,然后恢复为 Stroyboard 界面构建器中提供的标题。
这正常吗?
Do not use the label object to set the text color or the shadow color. Instead, use the setTitleColor:forState: and setTitleShadowColor:forState: methods of this class to make those changes.
同样,对于文本,您应该使用 setTitle:forState:
[sender.titleLabel setTitle:@"Clicked" forState:UIControlStateNormal];
我正在尝试设置一个相当简单的 Storyboard/Interface 构建器应用程序 UITableViewController
,带有两个原型单元格。
第一个原型单元显示主UILabel
上的信息,第二个原型单元包含一个UIButton
。我已将按钮的touchUpInside
操作连接到一些我想执行内容并修改按钮标题的代码:
- (IBAction)startButtonTouchUpInside:(UIButton *)sender {
[self doSomeStuff];
sender.titleLabel.text = @"Clicked";
}
然而,当我测试应用程序并单击 UIButton
时,UIButtons
标题会更改几分之一秒,然后恢复为 Stroyboard 界面构建器中提供的标题。
这正常吗?
Do not use the label object to set the text color or the shadow color. Instead, use the setTitleColor:forState: and setTitleShadowColor:forState: methods of this class to make those changes.
同样,对于文本,您应该使用 setTitle:forState:
[sender.titleLabel setTitle:@"Clicked" forState:UIControlStateNormal];