我创建了示例点击计数应用程序。但我不知道如何计算圈数。示例:当命中数 100 时,圈数为 1。当命中数 200 时,圈数为 2。我使用以下代码。谢谢。我是 xcode 初学者。
以下代码是 ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)plus {
counter=counter +1;
count.text = [NSString stringWithFormat:@"%i", counter];
}
-(IBAction)minus {
counter=counter -1;
count.text = [NSString stringWithFormat:@"%i", counter];
}
-(IBAction)zero {
counter=0;
count.text = [NSString stringWithFormat:@"%i", counter];
}
- (void)viewDidLoad
{
counter=0;
count.text=@"0";
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
以下代码是 ViewController.h #import
int counter;
@interface ViewController : UIViewController {
IBOutlet UILabel *count;
IBOutlet UILabel *lap;
}
-(IBAction)plus;
-(IBAction)minus;
-(IBAction)zero;
@end