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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:06:59+00:00 2026-05-18T21:06:59+00:00

I’m trying to add a feature into my app that allows the user to

  • 0

I’m trying to add a feature into my app that allows the user to toggle current date that is shown in US format (MM/DD/YYYY) to UK format (DD/MM/YYYY) and back.

I’m using a segment control to switch my UILabel (dateSlateLabel) between two separate timers (dateTimer_us & dateTimer_uk).

I’ve got everything working but whenever I toggle to the dateTimer_uk, dateTimer_us keeps fighting back, as if I haven’t killed it. When I say fighting back, I mean that I see the UK format with the US format blinking back and forth based on the timers’ timeInterval. So since my timers’ timeInterval is .01, I see a quick flashing of the US format over the UK format. Its clear to me that dateTimer_us is not being invalidated or something else is starting it back up. When I toggle to dateTimer_us, all seems fine, its just the other way around that is the problem, (when I toggle to dateTimer_uk). I figure something is wrong in my code/memory management but I can’t figure it out. I’ve scoured the web and spent two days on this problem.

Any ideas?

Note: I’ve tried using just one timer and an if else which checked the segmentControl status to drive the date format but that didn’t seem to work.

Here’s my code:

//////////////////////////////THIS CONTROLS THE DATE TIMER//////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
- (IBAction)toggleDateFormat {

    if(dateFormatSegmentControl.selectedSegmentIndex == 0) {


        [dateTimer_uk invalidate];
        [dateTimer_uk release];
        dateTimer_uk = nil;

        [self dateTimer_us];


    }
    else if (dateFormatSegmentControl.selectedSegmentIndex == 1) {


        [dateTimer_us invalidate];
        [dateTimer_us release];
        dateTimer_us = nil;

        [self dateTimer_uk];


    }

}







-(void)dateTimer_us {

    dateTimer_us = [[NSTimer scheduledTimerWithTimeInterval: .01
                                                     target: self
                                                   selector: @selector(displayDate_us)
                                                   userInfo: nil
                                                    repeats: YES] retain];

}
-(void)displayDate_us; {

    NSDateFormatter *formatter =
    [[[NSDateFormatter alloc] init] autorelease];
    NSDate *date = [NSDate date];


    [formatter setDateFormat:@"MM/dd/yyyy"];
    [dateSlateLabel setText:[formatter stringFromDate:date]];



}
-(void)dateTimer_uk {


    dateTimer_uk = [[NSTimer scheduledTimerWithTimeInterval: .01
                                                     target: self
                                                   selector: @selector(displayDate_uk)
                                                   userInfo: nil
                                                    repeats: YES] retain];
}           
-(void)displayDate_uk; {

    NSDateFormatter *formatter =
    [[[NSDateFormatter alloc] init] autorelease];
    NSDate *date = [NSDate date];


    [formatter setDateFormat:@"dd/MM/yyyy"];
    [dateSlateLabel setText:[formatter stringFromDate:date]];   

}
  • 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-18T21:07:00+00:00Added an answer on May 18, 2026 at 9:07 pm

    The design you’ve shown here is needlessly complicated. For one, you’re asking for an interval of one hundredth of a second to update a label which represents the current time. This is roughly one hundred times too often to be firing.

    Your design should be something like this:

    • Add an NSDateFormatter property to your view controller class. You don’t need to expose
      this property publicly.
    • In viewDidLoad,
      • alloc/init your NSDateFormatter property to whatever default setting you want, US or UK (you might read/write this preference from NSUserDefaults.
      • Start a timer on an interval of 1 second to call a method to update the label. This method should use the NSDateFormatter property, whatever value it is (the method doesn’t care) to render the date/time
    • In your callback method to toggle the time format,
      • release the NSDateFormatter property and alloc/init a new one
    • In viewDidUnload,
      • invalidate/release the NSTimer object
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but

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.