2012-11-30 11 views
8

Uczę się budować aplikacje na iPhone z XCode 4.5.2 i zauważyłem coś dziwnego. Jak widać pod adresem http://i.stack.imgur.com/purI8.jpg tekst wewnątrz jednego z przycisków nie jest wyświetlany w symulatorze iOS6. Próbowałem również przesunąć przycisk Enter w tym samym wierszu 0 i -, ale tekst we wszystkich trzech przyciskach linii zniknął. Ktoś wie, co jest przyczyną tego problemu i jak go rozwiązać? Oto kod:Symulator nie wyświetla tekstu przycisku

#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 
+0

możemy zobaczyć kod? – Max

+0

Tak, nie umieściłem tego, ponieważ tekst przycisku nie jest ustawiony za pomocą kodu, ale jeśli jest potrzebny, oto kod widoku. Działanie związane z przyciskiem to enterPressed. – Soel

+0

Czy rozwiązano problem? – ichanduu

Odpowiedz

0

Według 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 

Aby ustawić tytuły przycisk.

Więc w twoim przypadku:

- (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]; 

}

Powiązane problemy