私はある種のスコアボードに取り組んでいます。プレーヤーは、3 つの異なる値 (ギア、レベル、およびボーナス) を調整できます。これらを追加すると、総合的な強さが得られます。これらの各値は現在整数として出力されており、UILabel はそれぞれの整数を表示します。3 つの整数すべてを追加して UILabel に表示する方法がわかりません。私は現在 iOS 7 向けに開発していますが、これが現在サポートされている OS と大きく異なるとは思いません。どんな助けでも大歓迎です。
.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