开发者

Toggling the UILabel text on a UIButton programmatically

开发者 https://www.devze.com 2023-03-31 07:33 出处:网络
I created the following outlet IBOutlet UIButton *oneButton; and the following method when a button is pressed:

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.


Try something like this instead:

[oneButton setTitle:@"11" forState:UIControlStateNormal];
0

精彩评论

暂无评论...
验证码 换一张
取 消