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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:37:23+00:00 2026-05-14T14:37:23+00:00

I have looked at other answers and the docs. Maybe I am missing something,

  • 0

I have looked at other answers and the docs. Maybe I am missing something, or maybe I have another issue. I am trying to save a number on exiting the app, and then when the app is loaded I want to check if this value exists and take action accordingly. This is what I have tried:

To save on exiting:

- (void)applicationWillTerminate: (UIApplication *) application
{
 double save = [label.text doubleValue]; // This could be the issue

//double save = 3.5; // This works, it saves the value and loads it fine, so that is not the problem here.

 [[NSUserDefaults standardUserDefaults] setDouble: save forKey: @"savedNumber"];
 [[NSUserDefaults standardUserDefaults] synchronize]; 
}

To check:

- (IBAction)buttonclickSkip{

 double save = [[NSUserDefaults standardUserDefaults] doubleForKey: @"savedNumber"];

 if (save == 0) {

    [self performSelector:@selector(displayAlert) withObject:nil];

    test.enabled = YES;
    test.alpha = 1.0;

    skip.enabled = NO;
    skip.alpha = 0.0;

   }

 else {

 label.text = [NSString stringWithFormat:@"%.1f %%", save]; 
}

}

The problem is I always get my alert message displayed, the saved value is not put into the label so somehow == 0 is always true. Why would:

double save = [label.text doubleValue];

always equal zero? Before I close the app the number in that label is roughly 0.5% (it varies). If it makes any difference I am testing this on the iPhone simulator.

Many thanks,

Stu

  • 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-14T14:37:23+00:00Added an answer on May 14, 2026 at 2:37 pm

    The fact that you can hard-code the value and fetch it back means the problem definitely revolves around your interaction with the label.text and not your use of NSUserDefaults.

    Make sure that the label has not already been destroyed at the time you go to fetch its value. As the application is terminating it may have already brought down the view from which you are fetching the value.

    Another thing to try would be to get the actual text itself instead of asking the OS to convert the text value into a number first. If you print that out you may get some clue as to what is going on.

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

Sidebar

Related Questions

I've been trying this for a bit now and have looked at other answers
I have looked this up and what was described in other answers did not
I have looked at all the other answers to this question, but none of
I have looked at other questions and answers regarding this, but can't seem to
I have looked at some of the other posts made on similar topics but
I have looked for similar questions, but could find none other than the difference
I have looked at a lot of answers but have not found a satisfactory
I have looked all over the MySQL website and found no definitive answers. Is
I have looked through the other questions on here, and on other forums. The
Looked at some other similar answers on stack overflow, but no relevant answer was

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.