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

  • SEARCH
  • Home
  • 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 6622113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:21:52+00:00 2026-05-25T21:21:52+00:00

i created a simple project, with a + and – buttons that increase or

  • 0

i created a simple project, with a “+” and “-” buttons that increase or decrease a number inside a label.

I wanted to test the registerDefaults method, but if i click on the “home” button, and come back on the project from the simulator (with my app’s icon), the number is still the same on screen.

How can i test the user settings with this example? or is it something with the simulator, or would it work if i use the device and wait for the memory warning method to automatically refresh the project, and then it would work?

here’s a bit of my code :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    NSNumber *testValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"kRestore"];
    if (testValue){
        NSLog(@"already");
        viewController.myNum = (int)testValue;
    } else {
        NSLog(@"empty");
        viewController.myNum = 0;
    }

    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {

    NSNumber *num = [NSNumber numberWithInt:viewController.myNum];

    NSDictionary *savedNumber = [NSDictionary dictionaryWithObject:num forKey:@"kRestore"];
    [[NSUserDefaults standardUserDefaults] registerDefaults:savedNumber];
    [[NSUserDefaults standardUserDefaults] synchronize];

    NSLog(@"ok resign active");
}

Thanks

  • 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-25T21:21:53+00:00Added an answer on May 25, 2026 at 9:21 pm

    Calling -registerDefaults in applicationWillResignActive makes little sense. See my answer here on how registerDefaults works: How to register user defaults using NSUserDefaults without overwriting existing values?

    You use it to set the default values. To save a value that is not the default but the users preference, use the various -set.. methods provided.

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

Sidebar

Related Questions

I've created a simple winform project, added ClassLibrary with a single method that triggers
I created a simple Maven project (Packaging type - Jar) that has dependencies on
I've created a simple test project and a generic emulator TestDevice . However, I
I created a simple python project that serves up a couple of pages. I'm
I'm using NInject with NInject.Web.Mvc. To start with, I've created a simple test project
i created a simple project with zf and it works fine, but when i
I've created a simple Project model with four attributes: Project name:string description:text complete:boolean user_id:integer
I've created a very simple Enterprise Application project with about 7 entity beans and
i have created a simple public ref class in the vc++ project, which is
Okay, I was able to create a simple Windows Forms project that reproduces some

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.