我有按钮,bool作为切换。每当我更改切换时,我希望标题发生变化。但每当我更改切换时,标题不会自动更改。有人可以告诉我该怎么做吗?
代码:
@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;
}
答案 0 :(得分: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;
}
}