Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-30-2011, 04:01 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 33
smithms is on a distinguished road
Smile Region Formats, NSLocale, NSDate best practices

I have an app which populates a UITextField by selecting a date from a UIDatePicker. I noticed some isolated issues where the app had crashed after the user tapped the UITextField to revise a date using the DatePicker. What I now realize is that the user had changed the Region Format on the device after they had already entered a date into the textfield. When they returned later to revise the date, the DatePicker no longer recognized the date format.

What would be considered "best practice" for handling dates, region formats in this sort of situation?

Some of my ideas for handling this include one or more of the following:
  1. Use Try-Catch block to prevent a crash and reset the date to today's date. Then alert the user that the Region Format has changed since they last modified the date.
  2. Force a format onto the user using setLocale in a date formatter. Not crazy about this idea as I think the user should be free to select and change their preferred Region Format anytime.
  3. Store the Region Format in NSUserDefaults and check it against the current Region Format on the device each time the user changes a date. If they don't match then alter the date format to match the new region.

Not sure which way to go with this. I would appreciate your feedback.

Thanks in advance.
smithms is offline   Reply With Quote
Old 12-30-2011, 08:02 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by smithms View Post
I have an app which populates a UITextField by selecting a date from a UIDatePicker. I noticed some isolated issues where the app had crashed after the user tapped the UITextField to revise a date using the DatePicker. What I now realize is that the user had changed the Region Format on the device after they had already entered a date into the textfield. When they returned later to revise the date, the DatePicker no longer recognized the date format.

What would be considered "best practice" for handling dates, region formats in this sort of situation?

Some of my ideas for handling this include one or more of the following:
  1. Use Try-Catch block to prevent a crash and reset the date to today's date. Then alert the user that the Region Format has changed since they last modified the date.
  2. Force a format onto the user using setLocale in a date formatter. Not crazy about this idea as I think the user should be free to select and change their preferred Region Format anytime.
  3. Store the Region Format in NSUserDefaults and check it against the current Region Format on the device each time the user changes a date. If they don't match then alter the date format to match the new region.

Not sure which way to go with this. I would appreciate your feedback.

Thanks in advance.
The third option seems to make the most sense. Save the locale to defaults, and each time you return from the background, see if it's changed.

If it has, you could use the old locale to convert any saved date strings to the new format, and then start using the new format.

I think it would be reasonable to require the user to go through extra steps if they change locale. Changing the locale is a rare event.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 12-30-2011, 05:11 PM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 33
smithms is on a distinguished road
Default

That sounds like the best approach. Thanks for your help Duncan C.
smithms is offline   Reply With Quote
Reply

Bookmarks

Tags
nsdate, nslocale, region, uidatepicker, uitextfield

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 391
13 members and 378 guests
7twenty7, AppsBlogger, Creativ, Dalia, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:52 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0