Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding integers and displaying in a UILabel
    primarykey
    data
    text
    <p>I am working on a scoreboard of sorts. The player can adjust three different values (gear, level, and bonuses) that when added should provide a total strength. Each of these values is currently being output as an integer and a UILabel displays its' respective integer. I cannot figure out how to add all three integers and then display them on a UILabel. I am currently developing for iOS 7 but I don't imagine this to be terribly different for current supported OS's. Any help is greatly appreciated. </p> <p>.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; 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 </code></pre> <p>.m</p> <pre><code>#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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload