The simulator does not display the button text

I am learning to create iPhone apps with Xcode 4.5.2 and I noticed something strange. As you can see at http://i.stack.imgur.com/purI8.jpg , the text inside one of the buttons does not appear in the iOS6 simulator. I also tried moving the Enter button on the same line as 0 and -, but the text in all three buttons of the line disappeared. Does anyone know what is the cause of this problem and how to solve it? Here is the code:

#import "CalculatorViewController.h" #import "CalculatorBrain.h" @interface CalculatorViewController() @property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber; @property (nonatomic, strong) CalculatorBrain *brain; @end @implementation CalculatorViewController @synthesize display; @synthesize userIsInTheMiddleOfEnteringANumber; @synthesize brain = _brain; - (CalculatorBrain *)brain { if (!_brain) _brain = [[CalculatorBrain alloc] init]; return _brain; } - (IBAction)digitPressed:(UIButton *)sender { NSString *digit = [sender currentTitle]; if (self.userIsInTheMiddleOfEnteringANumber) { self.display.text = [self.display.text stringByAppendingString:digit]; } else { self.display.text = digit; self.userIsInTheMiddleOfEnteringANumber = YES; } } - (IBAction)enterPressed { [self.brain pushOperand:[self.display.text doubleValue]]; self.userIsInTheMiddleOfEnteringANumber = NO; } - (IBAction)operationPressed:(UIButton *)sender { if (self.userIsInTheMiddleOfEnteringANumber) [self enterPressed]; NSString *operation = [sender currentTitle]; double result = [self.brain performOperation:operation]; self.display.text = [NSString stringWithFormat:@"%g", result]; } @end 
+8
button ios6 ios-simulator
source share
1 answer

According to https://developer.apple.com/library/ios/documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/doc/uid/TP40006815-CH3-SW7

 - (void)setTitle:(NSString *)title forState:(UIControlState)state 

To customize the button names.

So in your case:

 - (IBAction)operationPressed:(UIButton *)sender{ .... [sender setTitle:[NSString stringWithFormat:@"%g", result] forState: UIControlStateNormal]; // lets assume you want the down states as well: [sender setTitle:[NSString stringWithFormat:@"%g", result] forState: UIControlStateSelected]; [sender setTitle:[NSString stringWithFormat:@"%g", result] forState: UIControlStateHighlighted]; 

}

0
source share

All Articles