以编程方式切换 UIButton 上的 UILabel 文本
当按下按钮时,我创建了以下插座
IBOutlet UIButton *oneButton;
和以下方法:
- (IBAction)digitPressed:(UIButton *)sender
{
NSString *digit = sender.titleLabel.text;
if ([digit isEqualToString:@"1"])
{
oneButton.titleLabel.text = @"11";
} else if ([digit isEqualToString:@"11"])
{
oneButton.titleLabel.text = @"1";
}
}
所以基本上我想在按下按钮时在 1 和 11 之间切换按钮的标题。通过设置断点,我看到程序执行了 oneButton.titleLabel.text = @"11"; 行。但标题实际上从未改变。 oneButton 连接到 IB 中的文件所有者。
I created the following outlet
IBOutlet UIButton *oneButton;
and the following method when a button is pressed:
- (IBAction)digitPressed:(UIButton *)sender
{
NSString *digit = sender.titleLabel.text;
if ([digit isEqualToString:@"1"])
{
oneButton.titleLabel.text = @"11";
} else if ([digit isEqualToString:@"11"])
{
oneButton.titleLabel.text = @"1";
}
}
So basically I want to toggle the title of the button between 1 and 11, whenever pressed. By putting breakpoint, I see that the program goes through the line oneButton.titleLabel.text = @"11"; but the title never actually changes. oneButton is connected to the file's owner in the IB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情:
Try something like this instead: