Hey everbody, im getting some trouble here. Well, im trying to pass a value from an string to an label. Im setting to setText:myString inside of function, but doesnt works. But when i try to set some random text inside of viewDidLoad, it works.
My function is called inside of viewDidLoad.
- (void)viewDidLoad {
//this works
[precoProd setText:@"hahaha"];
//here not
[MyViewClassName print];
[super viewDidLoad];
}
-(void) print{
float x = 500;
float c = x/3;
NSString *valorTotalParcelas;
if(c > 0) {
NSString *pVal = [NSString stringWithFormat:@"%0.2f", c];
NSString *cents = [pVal substringFromIndex:2];
NSString *reais = [pVal substringWithRange:NSMakeRange(0, 1)];
valorTotalParcelas = [[NSString alloc] initWithFormat:@"%@,%@",reais, cents];
}
// ---------------------
if(c > 9.99) {
NSString *pVal = [NSString stringWithFormat:@"%0.2f", c];
NSString *cents = [pVal substringFromIndex:3];
NSString *reais = [pVal substringWithRange:NSMakeRange(0, 2)];
valorTotalParcelas = [[NSString alloc] initWithFormat:@"%@,%@",reais, cents];
}
// ---------------------
if(c > 99.99) {
NSString *pVal = [NSString stringWithFormat:@"%0.2f", c];
NSString *cents = [pVal substringFromIndex:4];
NSString *reais = [pVal substringWithRange:NSMakeRange(0, 3)];
valorTotalParcelas= [[NSString alloc] initWithFormat:@"%@,%@",reais, cents];
}
// ---------------------
if(c > 999.99) {
NSString *pVal = [NSString stringWithFormat:@"%0.2f", c];
NSString *cents = [pVal substringFromIndex:5];
NSString *reais = [pVal substringWithRange:NSMakeRange(0, 4)];
valorTotalParcelas = [[NSString alloc] initWithFormat:@"%@,%@",reais, cents];
}
NSLog(@"FINAL VALUE ---> %@", valorTotalParcelas);
[precoProd setText:valorTotalParcelas];
}
What im doing wrong? Thanks!
valorTotalParcelasnever got sent thereleasemessage.