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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:06:48+00:00 2026-05-27T20:06:48+00:00

ok so this problem is kinda weird because the NSLog I have right in

  • 0

ok so this problem is kinda weird because the NSLog I have right in front of the line of code that should be printing out the text is returning the correct value.

Here’s the code:

-(void)setCurrentDate:(UILabel *)currentDate
{

NSInteger onDay = 1; //because if it's today, you are on day one, not zero... no such thing as a day zero

//get the nubmer of days left
if( [[NSUserDefaults standardUserDefaults] objectForKey:@"StartDate"] ){ //if there is something at the userdefaults
    onDay = [self daysToDate:[NSDate date]];
}//otherwise, onDay will just be one

self.theCurrentNumberOfDaysSinceStart = onDay;

NSLog(@"On day: %d", onDay); //this is returning the correct values....

//print it out on the label
[currentDate setText:[NSString stringWithFormat:@"On day: %d", onDay]];//echoes out the current day number 

}

So when the app first launches, everything is fine. The label updates and everything. The problem arises when I hit a button that basically grabs a new date. In the process, it runs this:

    //need to reload the "on day" label now
    [self setCurrentDate:self.currentDate];
    //and the "days left" label
    [self setDaysLeft:self.daysLeft];

Again, I’m thinking this should all be correct because the NSLog is returning the correct stuff. I’m thinking that the problem is with the last line in the first block of code I showed… the line with the setText.

thanks for all your help!

cheers,
Matt

  • 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-27T20:06:49+00:00Added an answer on May 27, 2026 at 8:06 pm

    If you used a nib

    When the nib loads and establishes all of it connections it… (From the Resource Programming guide)

    looks for a method of the form set OutletName: and calls it if such a method is present

    Therefore the nib will load and call setCurrentDate: passing in the unarchived UILabel as the parameter

    In your method you configure the UILabel using the local reference passed into the method

    [currentDate setText:[NSString stringWithFormat:@"On day: %d", onDay]];
    

    You at no point actually store a reference to this UILabel in an ivar, so technically you have leaked the label and as you have not set the ivar currentDate it will be initialised to nil. This is the danger of overriding a setter with an incorrect implementation.

    At some point in your method you should be setting your ivar to the passed in variable. A normal setter would look like this

    - (void)setCurrentDate:(UILabel *)currentDate;
    {
        if (_currentDate != currentDate) {
            [_currentDate release];
            _currentDate = [currentDate retain];
        }
    }
    

    But

    In your example I would not worry about this at all I would instead change this

    //need to reload the "on day" label now
    [self setCurrentDate:self.currentDate];
    

    to something like

    [self updateCurrentDate];
    

    The implementation would look something like:

    - (void)updateCurrentDate;
    {
        NSInteger onDay = 1;
    
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"StartDate"]) {
            onDay = [self daysToDate:[NSDate date]];
        }
    
        self.theCurrentNumberOfDaysSinceStart = onDay;
    
        [self.currentDate setText:[NSString stringWithFormat:@"On day: %d", onDay]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kind of a weird problem, but I have to create a search
This is kinda weird problem we came across with my friend. We located our
This is kind of weird problem. I have been using HttpWebRequest for a long
This question might be a bit sketchy because I do not have the code
This is kinda weird. I have the next query: SELECT * , GROUP_CONCAT( x.tag
I have a weird problem. I am making kinda my own framework like codeigniter
I have kind of a weird problem .. Something that isn't working on ff
I got a weird problem. I have a program that (does many things but
I'm sure this is the kind of problem other have solved many times before.
Here's a coding problem for those that like this kind of thing. Let's see

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.