Pages

Friday, January 11, 2013

Can't make UILabel receive NSString

I have a storyboard with a TabBar, that have two views on. On the first tab, I have one UITextField one Button and one UILabel. On the other tab, I have only one UILabel. The tho tabs (views) are controlled by the same ViewController. The thing is, with the codes I get the float value of what was inserted on the UITextField, make it into a string, and put this string on both labels, the issue is, only the label that is on the same view that the UITextField and the button that  recives the string, the other label that is on the other view don't recive anything...  

Codes:

.h

 

#import

 

@interface NotasFirstViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITextField *tfield;

- (IBAction)calcular:(id)sender;

-(IBAction)clicarFora:(id)sender;

-(IBAction)tirarteclado:(id)sender;

-(IBAction)calcsecondview:(id)sender;

@property (strong, nonatomic) NSString *valorstr;

@property (strong, nonatomic) IBOutlet UILabel *mostradordeteste;

@property (strong, nonatomic) IBOutlet UILabel *mostradordetestedois;

 

@end

 

 

.m

 

#import "NotasFirstViewController.h"

#import "NotasSecondViewController.h"

 

@interface NotasFirstViewController ()

 

@end

 

@implementation NotasFirstViewController

@synthesize valorstr;

 

- (void)viewDidLoad

{

    [super viewDidLoad];

  // Do any additional setup after loading the view, typically from a nib.

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (IBAction)calcular:(id)sender {

   

    float valor = [_tfield.text floatValue];

    NSString *valorstr = [[NSString alloc] initWithFormat:@"%.2f", valor];

    NSLog(@"%.2f", valor);

    NSLog(valorstr);

    _mostradordeteste.text = valorstr;

    _mostradordetestedois.text = valorstr;

   

}

 

-(IBAction)clicarFora:(id)sender{

   

    [_tfield resignFirstResponder];

   

}

-(IBAction)tirarteclado:(id)sender{

   

    [sender resignFirstResponder];

   

}

 

@end



View the original article here

0 comments:

Post a Comment