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 1012893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:00:53+00:00 2026-05-16T10:00:53+00:00

everyone, i have no idea why this doesn’t work hopefully someone here can help

  • 0

everyone, i have no idea why this doesn’t work hopefully someone here can help me out.
Here’s what i’m trying to do:

I’ve got two ViewControllers, lets call them secondViewController and firstViewController.
The firstViewController is shown when the application starts and it pushes the secondViewController.

Inside the secondViewController i defined a property.

Now i want to change this property in the firstViewController and then push the secondViewController but for some reason as soon as the secondViewController is pushed my property is reseted to zero…. why is this happening? heres my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 secondViewController.test = 2;
[self.navigationController pushViewController:secondViewController animated:YES];       

}

The test property in this example is just a simple NSInteger. Now as soon the secondViewController is pushed the “test” value is no longer two it’s zero…..
Why????

here’s the header file of my secondViewController:
#import

@interface secondViewController : UIViewController {

NSInteger test;

}

@property NSInteger test;

@end

here’s the .m file:

- (void) viewDidLoad{
NSLog(@"%i", self.test):
}
  • 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-05-16T10:00:54+00:00Added an answer on May 16, 2026 at 10:00 am

    If you’re checking it from the viewDidLoad test may not always be 2. I actually don’t understand why that is either. Example:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        SecondViewController viewController = [[SecondViewController alloc] init];
        viewController.test = 2;
        [self.navigationController pushViewController:viewController animated:YES];
    }
    
    // In SecondViewController
    
    - (void)viewDidLoad {
        NSLog(@"ViewDidLoad: %i", self.test);
    
        [super viewDidLoad];
    }
    
    - (void)viewWillAppear:(BOOL)animated {
        NSLog(@"ViewWillAppear: %i", self.test);
    
        [super viewWillAppear:animated];
    }
    

    This will sometimes result in the following output:

    ViewDidLoad: 0

    ViewWillAppear: 2

    But sometimes it may also result in the following output:

    ViewDidLoad: 2

    ViewWillAppear: 2

    So, I recommend you to use your variable in the ViewWillAppear-method instead of the ViewDidLoad-method.
    You should create your UIView‘s and stuff in the ViewDidLoad-method and adjust them to your test-variable in the ViewWillAppear-method :).

    It’s a bit confusing, I know, and it took me a few hours to figure out why my variable wasn’t set already too.

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

Sidebar

Related Questions

I'm just starting to work on a logging library that everyone can use to
This is a simple question: I know and have heard from almost everyone that
I'm trying to work out the best way to setup our multi-module Apache Maven
I have problem with mutexes I have this code and I dont any idea
Does anyone have any idea what is wrong with this create statement for mysql?
Hello everyone I have a problem. I want to do a GridView with a
Have a nice day everyone, I have something to ask your hel, to better
I have a central git repository that everyone pushes to for testing and integration,
everyone! I have sprite moving by action, what have health bar (progress bar). When
Hi everyone my problem today is I have a couple of buttons that slide

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.