我在网上关注了一个教程,我终于想出了如何让它发挥作用。唯一的缺点是,它只会添加一个位置,然后按下10次按钮才能再次使用。
这是我的代码:
ViewController.h:
@interface ViewController :UIViewController {
int counter;
IBOutlet UILabel *count;
}
-(IBAction)minus;
-(IBAction)plus;
-(IBAction)zero;
@end
And ViewController.m:
@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];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
counter=0;
count.text = @"0";
[super viewDidLoad];
}
@end
有关详细信息,请参阅我的视频:https://www.youtube.com/watch?v=P3yhtPHsc-4&feature=youtu.be