Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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


@interface NotasFirstViewController : UIViewController

@property (strong, nonatomic) IBOutletUITextField *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) IBOutletUILabel *mostradordeteste;

@property (strong, nonatomic) IBOutletUILabel *mostradordetestedois;


@end



.m


#import "NotasFirstViewController.h"

#import "NotasSecondViewController.h"


@interfaceNotasFirstViewController ()


@end


@implementation NotasFirstViewController

@synthesize valorstr;


- (void)viewDidLoad

{

[superviewDidLoad];


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

}


- (void)didReceiveMemoryWarning

{

[superdidReceiveMemoryWarning];

// 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{

[_tfieldresignFirstResponder];

}

-(IBAction)tirarteclado:(id)sender{

[sender resignFirstResponder];

}


@end

MacBook Pro, OS X Mountain Lion (10.8.2)

Posted on Jan 10, 2013 10:36 AM

Reply
5 replies

Can't make UILabel receive NSString

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.