5 Replies Latest reply: Jan 10, 2013 3:38 PM by xnav
gjmolter Level 1 Level 1 (0 points)

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 <UIKit/UIKit.h>

 

@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



MacBook Pro, OS X Mountain Lion (10.8.2)