非常感谢!
我正在开发一个应用程序,它有一个分接计数器来设置标签中的数量,然后标签值乘以分接计数器设置的数量,
标签将重置为0,但点击计数器不会,因此当用户点击计数器时,它会从最后一次计数开始
@implementation ViewController
//These are the tap counter buttons .m//
- (IBAction)oneClicker:(UIButton *)sender
{
counter++;
[_fourLabel setText:[NSString stringWithFormat:@"%d", counter]];
}
- (IBAction)oneAClicker:(UIButton *)sender
{
counter--;
[_fourLabel setText:[NSString stringWithFormat:@"%d", counter]];
// these are the calculate & reset buttons in .m //
- (IBAction)calculateButton:(UIButton *)sender
{
double total = ([self.fourLabel.text integerValue] * 4)+ ([self.sixLabel.text integerValue] * 6)+ ([self.ninetyFiveLabel.text integerValue] * 0.95)+ ([self.twoLabel.text integerValue] * 2)+ ([self.twoaLabel.text integerValue] * 2)+ ([self.threeLabel.text integerValue] * 3)+ ([self.oneFiftyLabel.text integerValue] * 1.5);
self.totalLabel.text = [NSString stringWithFormat:@"$%.2f",total];
}
- (IBAction)resetButton:(UIButton *)sender
{
self.fourLabel.text = @"0";
self.sixLabel.text = @"0";
self.ninetyFiveLabel.text = @"0";
self.twoaLabel.text = @"0";
self.twoLabel.text = @"0";
self.threeLabel.text = @"0";
self.oneFiftyLabel.text = @"0";
self.totalLabel.text = @"$0";
// self.fourLabel.text = @"";
}
// this is .h i will just show a few //
@interface ViewController : UIViewController
{
NSInteger counter;
}
@property (strong, nonatomic) IBOutlet UILabel *fourLabel;
- (IBAction)calculateButton:(UIButton *)sender;
- (IBAction)resetButton:(UIButton *)sender;
答案 0 :(得分:-1)
counter = 0;
这假设计数器是一个整数。如果是别的,只需相应调整。