-1

我有一个带有布尔值的按钮作为切换。每当我更改切换时,我都希望更改标题。但是每当我更改切换时,标题都不会自动更改。有人可以告诉我该怎么做吗?

代码:

@interface OrderController ()
{
    std::string currentValue;
    bool buttonToggle;
    NSString *orderNumber;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    buttonToggle = true;
}

- (IBAction)button1:(id)sender
{
    if (buttonToggle)
    {
        [sender setTitle:@"1" forState:UIControlStateNormal];
        currentValue += "1";
        orderNumber = [NSString stringWithCString:currentValue.c_str() encoding:NSUTF8StringEncoding];
    }
    else
    {
        [sender setTitle:@"A" forState:UIControlStateNormal];
        orderNumber = [NSString stringWithFormat:@"%@%@", orderNumber, @"A"];
        buttonToggle = true;
    }
}

- (IBAction)swipeUp:(id)sender
{
    buttonToggle = false;
}
4

1 回答 1

0

尝试这样做:

- (IBAction)button1:(UIButton *)sender  //line was changed
{
if (buttonToggle)
{
    sender.titleLabel.text=@"1"; //line was changed
    currentValue += "1";
    orderNumber = [NSString stringWithCString:currentValue.c_str() encoding:NSUTF8StringEncoding];
}
else
{
    sender.titleLabel.text=@"A"; //line was changed
    orderNumber = [NSString stringWithFormat:@"%@%@", orderNumber, @"A"];
    buttonToggle = true;
}
}
于 2013-08-18T12:17:25.690 回答