我創建了抽樣點擊計數應用程序。但我不知道如何計算一圈。例如:當命中數爲100時,圈數爲1.當命中數爲200圈時爲2.我使用以下代碼。謝謝。我是xcode初學者。Tap Count&Lap
下面的代碼是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;
[email protected]"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 #進口
int counter;
@interface ViewController : UIViewController {
IBOutlet UILabel *count;
IBOutlet UILabel *lap;
}
-(IBAction)plus;
-(IBAction)minus;
-(IBAction)zero;
@end
不知道,這個問題是什麼,但看起來像你有你在你的代碼需要的每一件事情。你能更具體地說明你想做什麼嗎?是上面的代碼工作,還是你想要做一些額外的事情,你不清楚。 – Srikanth
感謝您的評論。是的,這個代碼是可行的,但我需要一些額外的。例如:當命中數爲100時,圈數爲1.當命中數爲200圈時爲2.我使用以下代碼。謝謝。我是xcode初學者。 – ArnoHlaMoe
不確定您的圈數值是否可以根據計數器的值而改變,但無論是明智的,您只需在counter = counter + 1,counter = counter-1和counter = 0之後執行以下操作「一圈。text = [NSString stringWithFormat:%i「,counter/100];」這樣做的整數除法,並會給你正確的答案 – Srikanth