如何重置Xcode 5中的按钮/标签

时间:2014-08-15 00:01:17

标签: ios uibutton

我正在创建一个应用程序,您按下按钮然后它会在标签中显示一个标记。然后我有一个按钮来清除信息。

实施例。如果我按下按钮,它将添加" 1"到标签" labelTwo"。用户按下按钮5次,labelTwo将显示" 5"。我点击" clearButton"它清除了它。

我的问题是,清除后,如果我按下按钮2,labelTwo将不会在" 1"但继续在" 6"好像我从未清除它。

谢谢

 - (IBAction)buttonFour:(id)sender {
    self.four += 1;
    [self.labelFour setText:[NSString stringWithFormat:@"%d", self.four]];
}

- (IBAction)buttonThree:(id)sender {
    self.three += 1;
    [self.labelThree setText:[NSString stringWithFormat:@"%d", self.three]];
}

- (IBAction)buttonTwo:(id)sender {
    self.two += 1;
    [self.labelTwo setText:[NSString stringWithFormat:@"%d", self.two]];
}

- (IBAction)buttonOne:(id)sender {
    self.one += 1;
    [self.labelOne setText:[NSString stringWithFormat:@"%d", self.one]];
}

- (IBAction)clearButton:(id)sender {
    self.clear = 0;
    [self.clearFour setText:[NSString stringWithFormat:@"%d", self.clear]];
    self.clear = 0;
    [self.clearThree setText:[NSString stringWithFormat:@"%d", self.clear]];
    self.clear = 0;
    [self.clearTwo setText:[NSString stringWithFormat:@"%d", self.clear]];
    self.clear = 0;
    [self.clearOne setText:[NSString stringWithFormat:@"%d", self.clear]];
    self.clear = 0;
    [self.clearTotal setText:[NSString stringWithFormat:@"%d", self.clear]];
}

- (IBAction)totalOne:(id)sender {
    self.oneTotal +=1; [self.total setText:[NSString stringWithFormat:@"%d", self.oneTotal]];
}

- (IBAction)totalTwo:(id)sender {
    self.oneTotal +=1; [self.total setText:[NSString stringWithFormat:@"%d", self.oneTotal]];
}

- (IBAction)totalThree:(id)sender {
    self.oneTotal +=1; [self.total setText:[NSString stringWithFormat:@"%d", self.oneTotal]];
}

- (IBAction)totalFour:(id)sender {
    self.oneTotal +=1; [self.total setText:[NSString stringWithFormat:@"%d", self.oneTotal]];
}

1 个答案:

答案 0 :(得分:0)

您需要在self.two方法中将clearButton:的值设置为零。将其添加到您的clearButton:方法:

self.one = 0;
self.two = 0;
self.three = 0;
self.four = 0;
self.five = 0;