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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:04:20+00:00 2026-06-07T03:04:20+00:00

This is probably an easy question, but I’m a newbie, so I’m drawing a

  • 0

This is probably an easy question, but I’m a newbie, so I’m drawing a blank.

I have a 2D graphical application whose graphics (implemented in drawRect) depend upon the date. When the date changes, the graphics change, so I figure I need to call

[myView setNeedsDisplay: YES];

when the date changes. I’ve seen code for timers, but this doesn’t seem to be a timer type of scenario. How would I check if the local date has changed, and what class would I put that code in? I assume it would go in the .m file for my main view.

Besides automatically triggering upon a change of date, eventually, the app will need to trigger upon user input (perhaps a button to go forward or backward one day or upon a date picker selection).

The graphics render just fine as is, but I’ve not coded any date trigger, so while the drawRect code is date specific, it doesn’t change when the date changes.

P.S. My basic question, above, has been answered, but now that I go to implement it, I realize I have another issue. I ought to have a property somewhere to track the date whose configuration is currently being displayed. The obvious idea is to add a property to the main view holding an NSDate object. But the way I’ve coded things, the calculations are done by a method in a subview class. So the question is, how to update the NSDate property of the main view from the subview. An alternative would be to add an NSDate property to the subview, but there are multiple such subviews, and that would seem to be redundant. Any opinion on this?

  • 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-07T03:04:21+00:00Added an answer on June 7, 2026 at 3:04 am

    You can use an NSTimer for this. First, though, you need to figure out when that NSTimer should fire. You can use NSDate, NSCalendar, and NSDateComponents for that:

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *todayComponents = [calendar components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
    NSDate *today = [calendar dateFromComponents:todayComponents];
    // today is the start of today in the local time zone.  Note that `NSLog`
    // will print it in UTC, so it will only print as midnight if your local
    // time zone is UTC.
    
    NSDateComponents *oneDay = [[NSDateComponents alloc] init];
    oneDay.day = 1;
    NSDate *tomorrow = [calendar dateByAddingComponents:oneDay toDate:today options:0];
    

    Once you have tomorrow, you can set a timer to fire on that date:

    NSTimer *timer = [[NSTimer alloc] initWithFireDate:tomorrow interval:0 target:self selector:@selector(tomorrowTimerDidFire:) userInfo:nil repeats:NO];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    // The run loop retains timer, so you don't need to.
    

    And in tomorrowTimerDidFire::

    - (void)tomorrowTimerDidFire:(NSTimer *)timer {
        [myView setNeedsDisplay:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably an easy question but I can't find the answer... I have
This is probably an easy question but I can't figure it out. I have
Quick question- I know this is probably really easy, but my excel skills have
Ok, I think this is probably an easy question but for the life of
This is probably an easy question, but I'd like to iterate through the tags
This is probably an easy question... I have 4 source versions of the same
This question is probably easy to solve, but here it comes. I would like
I am new to Rails so this is probably an easy question but can't
This is probably a super easy question but I'm banging my head on it
This is probably a really easy question, but I can't find anything that works.

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.