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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 07-08-2010, 05:32 AM   #1 (permalink)
aLoggers.com
 
Join Date: May 2009
Location: Minsk, Belarus
Posts: 17
Send a message via Skype™ to zaplitny
Default UIDatePicker bug in iOS 4

I've found very strange bug of UIDatePicker in iOS4.

It seems that UIDatePicker timeZone is set during project build or something like this. You can reproduce it by setting

Code:
NSLog(@"Date : %@", [[NSDate date] description]);
datePicker.date = [NSDate date];
If you build it and run first time - all is ok. Then change your timezone to another and run it again (without cleaning targets) - in log you'll see correct date (according to new time zone) but in datePicker you'll see other date (from prev time zone). If you clean targets and rebuild it all is ok.

The workaround for this is to set current timezone to datePicker:
Code:
datePicker.timeZone = [NSTimeZone localTimeZone];
It's very strange behavior
zaplitny is offline   Reply With Quote
Old 07-09-2010, 03:56 AM   #2 (permalink)
Registered Member
 
brendand's Avatar
 
Join Date: Aug 2008
Posts: 223
Default

I also had this problem with my app. I've just applied this fix to it and it works great. Thanks for posting the solution.


Quote:
Originally Posted by zaplitny View Post
I've found very strange bug of UIDatePicker in iOS4.

It seems that UIDatePicker timeZone is set during project build or something like this. You can reproduce it by setting

Code:
NSLog(@"Date : %@", [[NSDate date] description]);
datePicker.date = [NSDate date];
If you build it and run first time - all is ok. Then change your timezone to another and run it again (without cleaning targets) - in log you'll see correct date (according to new time zone) but in datePicker you'll see other date (from prev time zone). If you clean targets and rebuild it all is ok.

The workaround for this is to set current timezone to datePicker:
Code:
datePicker.timeZone = [NSTimeZone localTimeZone];
It's very strange behavior
brendand is offline   Reply With Quote
Old 07-09-2010, 09:11 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 14
Default UiDatePicker default behaviour

I also had this problem since building my latest update binaries with the new SDK 4.
Interface Builder doesn't even have a field to set the time zone of the UIDatePicker so it has to be done in ViewDidLoad as suggested.
The documents say that leaving it nil and not setting a value would have the same behaviour as
datePicker.timezone = [NSTimeZone localtimezone];
but it definitely doesn't.
Not very helpful of Apple to change the default behaviour of this commonly used object. There must be a lot of app developers hit by this one and now receiving emails from users of their apps in different time zones complaining about their pickers displaying incorrect values.
Any one else out there had issues?
stevetrollope is offline   Reply With Quote
Old 07-09-2010, 06:37 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 6
Default

I'm also seeing this issue. Frustrating!
alku83 is offline   Reply With Quote
Old 07-09-2010, 08:33 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 142
Default

My HoursTracker apps ran into this with the 2.0 (iOS 4) update. I got probably 500 emails about it from users who were very frustrated, and some 1 star reviews.

Apple rushed a 2.0.1 update that includes setting the timezone (and locale) to the current ones. That works around the problem.

I created a simple sample project that demonstrates the problem and submitted it to Apple as a iOS 4 bug.

Note that this bug only comes up if you use a .xib -- the picker behaves properly if you add it in code.
cribasoft is offline   Reply With Quote
Old 07-14-2010, 12:38 PM   #6 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 101
Default

I'm encountering similar problem on simulator iOS 4.0 (SDK 4 final) without IB and it hasn't to do with timezone change after build (I deleted build, cleaned targets and made rebuild).

Code:
  NSLog(@"birthday=%@",birthdayDate);
  NSLog(@"now     =%@",[NSDate date]);
  [datePicker setDate:bbirthdayDate animated:NO];   
  datePicker.timeZone = [NSTimeZone localTimeZone];
  datePicker.locale   = [NSLocale currentLocale]; 
  datePicker.calendar = [NSCalendar currentCalendar];
  datePicker.datePickerMode = UIDatePickerModeDate;
  [datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
NSLog diplays correctly this:
Code:
birthday=2000-07-16 12:00:00 +0300
now     =2010-07-14 19:30:46 +0300
But DatePicker displays 2000-07-15. However on iPad simulator (3.2) and iPhone 3.1.2 it works fine. Seems to be a problem on iOS4. It didn't help to set localTimeZone. Btw - my MacBook and simulator is working with timezone of Ukraine (Kiev). I don't have a device with iOS4 to test it.
dobry is offline   Reply With Quote
Old 07-15-2010, 02:56 AM   #7 (permalink)
aLoggers.com
 
Join Date: May 2009
Location: Minsk, Belarus
Posts: 17
Send a message via Skype™ to zaplitny
Default

Quote:
Originally Posted by dobry View Post
I'm encountering similar problem on simulator iOS 4.0 (SDK 4 final) without IB and it hasn't to do with timezone change after build (I deleted build, cleaned targets and made rebuild).

Code:
  NSLog(@"birthday=%@",birthdayDate);
  NSLog(@"now     =%@",[NSDate date]);
  [datePicker setDate:bbirthdayDate animated:NO];   
  datePicker.timeZone = [NSTimeZone localTimeZone];
  datePicker.locale   = [NSLocale currentLocale]; 
  datePicker.calendar = [NSCalendar currentCalendar];
  datePicker.datePickerMode = UIDatePickerModeDate;
  [datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
NSLog diplays correctly this:
Code:
birthday=2000-07-16 12:00:00 +0300
now     =2010-07-14 19:30:46 +0300
But DatePicker displays 2000-07-15. However on iPad simulator (3.2) and iPhone 3.1.2 it works fine. Seems to be a problem on iOS4. It didn't help to set localTimeZone. Btw - my MacBook and simulator is working with timezone of Ukraine (Kiev). I don't have a device with iOS4 to test it.
I reproduced it too, but I think it's other type of bug that is connected with mode of picker. If you change date picker mode to UIDatePickerModeDateAndTime it will show correct value
__________________
aTimeLogger - application for tracking your everyday activities
zaplitny is offline   Reply With Quote
Old 07-15-2010, 01:35 PM   #8 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 5
Default

Dobry,

Thanks for starting this thread. I've been challenged by this as well. Since my app is frequently used for tracking time across time zones, this is a big problem for me. In viewWillAppear:

Code:
datePicker.timeZone = [NSTimeZone localTimeZone];
Setting localTime Zone improved the situation, but the problem cropped up again. I played around with a number of things and I get the most consistent results with:

Code:
datePicker.timeZone = [NSTimeZone defaultTimeZone];
Although Today (as displayed in blue on the picker) is not always correct, the correct date is displayed when the time zone changes. Quitting the app and starting up again (iOS 4) always restores the correct behavior to the datePicker. So this problem is only a problem for me because the app is "freeze dried", the time zone changes, the app is brought to the foreground and the datePicker doesn't update for the new localTimeZone.

John
2ndSegment is offline   Reply With Quote
Old 07-16-2010, 01:58 AM   #9 (permalink)
iOS / MacOS Developer
 
bharath2020's Avatar
 
Join Date: Oct 2008
Location: Bengaluru
Posts: 150
Default

Thanks Zaplitny..

It Saved my Time :-)
__________________
Bharath
iOS Blog : http://iphone2020.wordpress.com
bharath2020 is offline   Reply With Quote
Old 09-09-2010, 09:43 AM   #10 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 101
Default

I solved the problem I mentioned by setting datePickerMode before the date.
dobry is offline   Reply With Quote
Old 10-25-2010, 07:30 AM   #11 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 11
Default some sample code for connecting to a data base and displaying a retrieved data

please post some code asap.
adarshrao is offline   Reply With Quote
Old 12-09-2010, 04:03 AM   #12 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: New Delhi
Posts: 1
Thumbs up DatePicker problem with Timezone

Hi All,
whatever my experiences say that the following code is more stable solution of the following problem, it picks your device time zone and even format(12 hrs/24 hrs)

Code:
datePicker.timeZone = [NSTimeZone systemTimeZone];

Note : if some one has better solution, let me know on tahir.faridi@halosys.com

Thanks
Tahir Faridi
tahir.faridi is offline   Reply With Quote
Old 01-03-2011, 08:14 AM   #13 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Jakarta Indonesia
Posts: 1
Unhappy Help please

Hi all,

I have same problem about UIDatePicker in iOS SDK 4.2, but it seem just for iPad Simulator 4.2. So the date that I choose in UIDatePicker become one day before. But it become normal if I make "pickerDate.datePickerMode = UIDatePickerModeDateAndTime". My apps just need for "UIDatePickerModeDate". Anyone can help me?

If anyone has a solution, please tell me in deenna_vargilz@yahoo.com


Thanks

Dina
deenna_vargilz is offline   Reply With Quote
Reply

Bookmarks

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: 454
12 members and 442 guests
clerisysolutions, dana0550, dapis, darbsllim, dre, Harolano, Hyde, lbert, leesdesjardins, marshusensei, Objective Zero, RickSDK
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 157,851
Threads: 88,914
Posts: 379,294
Top Poster: BrianSlick (7,072)
Welcome to our newest member, darbsllim
Powered by vBadvanced CMPS v3.1.0

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