PDA

View Full Version : UIDatePicker on the iPad not changing




Phantom1812
Jul 28, 2010, 05:35 AM
Ok, I've done a lot of Googling, but I must be getting something wrong!

I an writing an iPad-specific version of our iPhone application, so copying/pasting a bunch of code. I mention this, because things are working fine on our live app - this behavior is on our test iPad device running though XCode 3.2.3, OS3.2.1 (7B405)

I have a UIDatePicker added in IB with the following settings :

mode : Date
Locale : English (United Kingdom)
Interval : 5 minutes
Date : 28/07/2010 09:00
No constraints
Timer : 0

So basically just all default. I have attached the Value Changed property to the following method :


-(IBAction)handleDOBselect:(id)sender {

NSLog(@"PICKER OUTPUT : %@", [(UIDatePicker *)sender date]);


}


As you see, it couldn't be simpler - just log the current selected date. However, as soon as you select a date, the log shows "PICKER OUTPUT : 2010-07-28 09:00:30 +0100" and then no matter how much you change the date, the output is ALWAYS "PICKER OUTPUT : 2010-07-28 09:00:30 +0100"

I stress that this is not causing a crash and has been set up the same as a live iPhone app which currently works perfectly (the date is updated on each value change and I can use that elsewhere.

Can anyone offer a div like me, a little guidance as to why my UIDatePicker...erm doesn't pick dates on the iPad?

Cheers,

P.



dejo
Jul 28, 2010, 09:21 AM
I just put together a quick test project and it seems to output the correct dates for me. Hmm...

Phantom1812
Jul 28, 2010, 09:36 AM
That's what is so strange - the code is a cut and paste job, from working code.

Is there any way of me getting my hands on your test project? I'm curious what setting/settings I have changed without realising.

My environment info is below :


Developer Information:

Version: 3.2 (10M2262)
Location: /Developer
Applications:
Xcode: 3.2.3 (1688)
Interface Builder: 3.2.3 (788)
Instruments: 2.7 (2529)
Dashcode: 3.0.1 (330)
SDKs:
Mac OS X:
10.5: (9L31a)
10.6: (10M2262)
iPhone OS:
3.2: (7B405)
4.0: (8A306)
iPhone Simulator:
3.2: (7W367a)
4.0: (8A306)


Could I be suffering from a bug somewhere?

P~

dejo
Jul 28, 2010, 09:46 AM
Is there any way of me getting my hands on your test project? I'm curious what setting/settings I have changed without realising.
Attached.

Phantom1812
Jul 28, 2010, 10:24 AM
Thank you hugely, mate - right, that works perfectly in the simulator, but mine still acts strangely in the simulator and on the device.

I will try creating a blank project the same as yours and seeing what happens. Then I guess it's a case of starting to strip my main app back until I can get it working.

I will post the solution here, should I find it - unless it's bloody embarrassing, of course! :D

Thanks again. Much appreciated.

P~

dejo
Jul 28, 2010, 10:36 AM
I will post the solution here, should I find it - unless it's bloody embarrassing, of course! :D
Ah, no worries, mate. We all have our "moments". :D

Thanks again. Much appreciated.
You're welcome. And good luck! I think many of us know how frustrating these obscure bugs can be. :mad:

Phantom1812
Jul 28, 2010, 11:16 AM
There is definitely a rabbit off somewhere. :(

I created a brand new solution - added a picked in IB, added the function above, hooked up and it worked great.

So, I deleted everything relating to the picker on my app and rebuilt.

I then have added a new picker to the view (testPicker and added a test function in, exactly the same as the one above except called -(IBAction)testDate:(id)sender; and guess what...that's right, the picker feeds back today's date only.

every time I change a date barrel in the picker, a line is added to the console as you would expect, but it's always 'now' and never the date actually selected.

I am absolutely at a loss as to what the hell is going on. To the point where I am wondering if there is some strange corruption happening and I need to delete my files and create new ones from scratch.

Either that or write to Jim'll Fix It...

P~

Phantom1812
Jul 28, 2010, 11:37 AM
OK, scary update number 2.

I have just created a new view controller and added it to my app project. Fresh out the box, I added a date picker and linked the value changed to a function the same as the one above - the logged date is always today's date.

The fact I can create a fresh project and get it working suggests it's not a bug in XCode, but it's starting to look like I have a corrupt project/build.

Any suggestions for 'cleaning' my project without having to bin everything and start again? Should I be deleting any build directories or running any commands or anything?

Cheers all. My arse is pinching a little on this one as there is such a lot of work I potentially have to do all over again.

P~

dejo
Jul 28, 2010, 12:01 PM
Clean All Targets?

Phantom1812
Jul 28, 2010, 12:06 PM
Yeah, that's not making any difference.

Does it sound like I'm going out of my mind here?

I have found one other reference to this on t'internet and it's someone at the end of a thread on another forum describing exactly the same behavior as above - but there are no further posts past his last one.

dejo
Jul 28, 2010, 12:11 PM
How new is this project that you are having issues with? I'm wondering because perhaps it is an issue with some difference between an older, existing project created in the past and a fresh, new project created with, possibly, an newer SDK.

Also, how much work do you think it'll be to just "recreate" the project, as it were? Daunting?

Phantom1812
Jul 28, 2010, 02:51 PM
Hmmm, I do think this it was created in the old version of the SDK (pre-last update), but i have only just got to the only view ,controller i have with a date picker on it.

It would take me about a day and a half to create a new project and copy the stuff across, but I'm not entirely sure i just won't run into the same issue.

It's honestly a really unusual thing. Simpply adding a new UIViewController and adding a picker to that in the project, does not work either. It needs a whole new project.

Argh!!!!!!!!!

Thanks for listening so far, mate. I actually wish this was the embarrassing thing i was fearing when i started the thread! At least it would work now.

Guess i need to get back to it first thing in the morning.

P~

Phantom1812
Jul 29, 2010, 09:24 AM
Just an update for anyone else who has followed this.

I believe the issue seems to be that the UIViewController that the picker is on, is being initialized in a new thread - basically, the entire UIView Controller is no longer running on the main thread. If I put a date picker on my root UIViewController, the date is fed back correctly. As soon as the view/UIViewController on which the date picker exists is init in a new thread, the date picker no longer passes back the date it shows.

This quirk ONLY seems to be happening when running on the iPad OS. It's been working great on the iPhone.

I am currently still working on this, but surely this HAS to be a bug, no?

P~

Phantom1812
Jul 29, 2010, 09:50 AM
Yup - that's it - moved the initialization of the UIViewController that the picker was on, onto the main thread and the picker now feeds back the date as shown - not just the date it was initialized with.

That was a fun couple of days...thanks for everyone's help. Much, much appreciated.

PhoneyDeveloper
Jul 29, 2010, 10:16 AM
Most of UIKit isn't thread safe. You can't access UIKit classes from background threads at all. If you try the results are unpredictable.

Phantom1812
Jul 29, 2010, 10:21 AM
unpredictable.

Perhaps the best word you could have chosen.

Had it been a consistent issue, I would never have got this far - I would have done things differently from the start. But it's worked up until now.

Oh well...you live and learn...and stab and cry.