我正在制作各种记分牌。玩家可以调整三个不同的值(装备、等级和奖励),添加这些值后应提供总强度。这些值中的每一个当前都作为整数输出,并且 UILabel 显示其各自的整数。我不知道如何添加所有三个整数,然后将它们显示在 UILabel 上。我目前正在为 iOS 7 开发,但我不认为这对于当前支持的操作系统会有很大的不同。任何帮助是极大的赞赏。
。H
#import <UIKit/UIKit.h>
int levelCount;
int gearCount;
int oneShotCount;
int totalScoreCount;
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *totalScore;
@property (weak, nonatomic) IBOutlet UILabel *playerName;
@property (weak, nonatomic) IBOutlet UILabel *levelNumber;
@property (weak, nonatomic) IBOutlet UILabel *gearNumber;
@property (weak, nonatomic) IBOutlet UILabel *oneShotNumber;
- (IBAction)levelUpButton:(id)sender;
- (IBAction)levelDownButton:(id)sender;
- (IBAction)gearUpButton:(id)sender;
- (IBAction)gearDownButton:(id)sender;
- (IBAction)oneShotUpButton:(id)sender;
- (IBAction)oneShotDownButton:(id)sender;
@end
.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
int ans = levelCount + gearCount + oneShotCount;
self.levelNumber.text = [NSString stringWithFormat:@"%i", ans];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)levelUpButton:(id)sender {
levelCount = levelCount + 1;
self.levelNumber.text = [NSString stringWithFormat:@"%i", levelCount];
}
- (IBAction)levelDownButton:(id)sender {
levelCount = levelCount - 1;
self.levelNumber.text = [NSString stringWithFormat:@"%i", levelCount];
}
- (IBAction)gearUpButton:(id)sender {
gearCount = gearCount + 1;
self.gearNumber.text = [NSString stringWithFormat:@"%i", gearCount];
}
- (IBAction)gearDownButton:(id)sender {
gearCount = gearCount - 1;
self.gearNumber.text = [NSString stringWithFormat:@"%i", gearCount];
}
- (IBAction)oneShotUpButton:(id)sender {
oneShotCount = oneShotCount + 1;
self.oneShotNumber.text = [NSString stringWithFormat:@"%i", oneShotCount];
}
- (IBAction)oneShotDownButton:(id)sender {
oneShotCount = oneShotCount - 1;
self.oneShotNumber.text = [NSString stringWithFormat:@"%i", oneShotCount];
}
@end