Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:24:02+00:00 2026-06-17T07:24:02+00:00

I have two views and two classes. On the first view, controlled by the

  • 0

I have two views and two classes. On the first view, controlled by the first class I have a textfield and a button. On the second view controlled by the second class I have two labels. I tried to make one label receive the value I put on the text field, and the other label this value divided by 100. But on both cases I get 0.00, I don’t know why!

firstclass.h

#import <UIKit/UIKit.h>

@interface NotasViewController : UIViewController{

}

-(IBAction)calcular:(id)sender;
-(IBAction)clicarFora:(id)sender;
-(IBAction)recuarTeclado:(id)sender;
@property (strong, nonatomic) IBOutlet UITextField *inserirTF;


@end

fisrtclass.m

#import "NotasViewController.h"
#import "resultadoViewController.h"

@interface NotasViewController ()

@end

@implementation NotasViewController
@synthesize inserirTF;

- (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 = [inserirTF.text floatValue];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    resultadoViewController *second = [storyboard instantiateViewControllerWithIdentifier:@"resultado"];
    second.resultadoFloatValor = valor;
    NSLog(@"%.2f", second.resultadoFloatValor);
}

-(IBAction)recuarTeclado:(id)sender{

    [sender resignFirstResponder];

}

-(IBAction)clicarFora:(id)sender{

    [inserirTF resignFirstResponder];

}

@end

secondclass.h

#import <UIKit/UIKit.h>

@interface resultadoViewController : UIViewController{

    float resultadoFloatValor;

}

@property float resultadoFloatValor;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelValor;
@property (strong, nonatomic) IBOutlet UILabel *resultadoLabelQtd100;

@end

secondclass.m

#import "resultadoViewController.h"

@interface resultadoViewController ()

@end

@implementation resultadoViewController
@synthesize resultadoFloatValor, resultadoLabelValor, resultadoLabelQtd100;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    NSString *resultadoStringValor = [[NSString alloc] initWithFormat:@"%.2f", resultadoFloatValor];
    NSLog(@"%.2f", resultadoFloatValor);
    NSLog(@"%@", resultadoStringValor);
    resultadoLabelValor.text = resultadoStringValor;

    int resultadoIntResto100 = resultadoFloatValor/100;

    if (resultadoIntResto100 > 0) {

        NSString *resultadoStringQtd100 = [[NSString alloc] initWithFormat:@"%i", resultadoIntResto100];
        resultadoLabelQtd100.text = resultadoStringQtd100;

    }

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

You’ll see 3 NSLogs on my code. For testing, I put 54 on my textfield. The Output was like this:

2013-01-12 21:15:27.020 Divisorreal[21843:c07] 54.00
2013-01-12 21:15:27.023 Divisorreal[21843:c07] 0.00
2013-01-12 21:15:27.023 Divisorreal[21843:c07] 0.00

PS: All my Outlets are correctly connected to the UILabels.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:24:02+00:00Added an answer on June 17, 2026 at 7:24 am

    Best guess:

    It looks like you are setting resultadoFloatValor after viewDidLoad is called.

    Implement prepareForSegue: and set the value there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
I have two views, one view takes the whole screen, the second view covers
i have made two view classes in first view class i am making more
I have two classes. In my first class i have table view which contains
I have two views within one .xib (one view for landscape, another for portrait).
I have two views that I would like to combine into one. The first
I have two views.In first view, I have a table view and I am
I have two View Controller classes Class A & Class B There is a
I have two view controller classes in my application delegate. I can change from
I have two views, both under the NavigationController. I don't want View 1 (on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.