2012-11-30 10 views
8

Sto imparando a creare app per iPhone con XCode 4.5.2 e ho notato qualcosa di strano. Come puoi vedere all'indirizzo http://i.stack.imgur.com/purI8.jpg il testo all'interno di uno dei pulsanti non viene visualizzato nel simulatore iOS6. Ho anche provato a spostare il pulsante Invio nella stessa riga di 0 e -, ma il testo in tutti e tre i pulsanti della linea è scomparso. Qualcuno sa qual è la causa di questo problema e come risolverlo? Ecco il codice:Il simulatore non mostra il testo del pulsante

#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

Possiamo vedere il tuo codice? – Max

+0

Sì, non l'ho inserito perché il testo del pulsante non è impostato tramite il codice, ma se ne hai bisogno, ecco il codice della vista. L'azione relativa al pulsante è enterPressed. – Soel

+0

Il problema è risolto? – ichanduu

risposta

0

Secondo 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 

Per impostare i titoli dei pulsanti.

Quindi nel tuo caso:

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

}

Problemi correlati