Trouble using DatePicker

Discussion in 'iOS Programming' started by slammers, Sep 28, 2008.

  1. slammers macrumors newbie

    Joined:
    Sep 28, 2008
    #1
    I created a simple view in Interface builder with a UItextfield and UIDatePicker.

    I open the view and set the DatePicker date in the ViewDidLoad method. However, when the view loads the picker displays a strange date like November 28 0002.

    I setup a method to respond to the date change event and this method is called three times while the view is loading. Each time the method is called I checked the date of the DatePicker and each time it has the correct date.

    I am at total loss why this is happening. Does anyone have any idea what would cause this?

    Thanks
    Shawn
     
  2. mozmac macrumors 6502

    mozmac

    Joined:
    Apr 28, 2005
    Location:
    Austin, TX
    #2
    Did you ever figure out this problem? I am having it right now. I'll probably go back and recreate some things to see if I messed up somewhere along the line. But I would like to hear what you did to fix this.
     
  3. slammers thread starter macrumors newbie

    Joined:
    Sep 28, 2008
    #3
    Unfortunately, no. I did not find a solution for this so I had to do it a different way. I hide the date picker when the view loads and then pop it up when the user clicks in a UITextField control. This way the picker does all its weird stuff while hidden. When the user clicks the text field I set the picker date and set its hidden property to false. It then gets shown with its correct date.

    Shawn
     
  4. mozmac macrumors 6502

    mozmac

    Joined:
    Apr 28, 2005
    Location:
    Austin, TX
    #4
    I found the problem. Looks like it was a bug in version 2.0 of the SDK. When I loaded it to my iPod Touch running 2.1, everything worked fine. In your Xcode project, there is a drop down list on the top left where you select if you want to run your app in the simulator or on a device. Make sure everything in there is set to use 2.1, including the "Active Executable." As you switch between Simulator and Device, the Active Executable defaults back to 2.0, so you'll need to set it 2.1 again.
     
  5. Brendan.Porter macrumors member

    Joined:
    May 19, 2007
    Location:
    Between tourists, corn, and windmills.
    #5
    I created a UIDatePicker based app, and I discovered some strange things happening when I calculated the difference between two different NSDates. The bug exists in the SDK, specifically with placing a UIDatePicker in the app with InterfaceBuilder. I don't know why or how this happens, but to fix this you need to remove the UIDatePicker from Interface Builder and instead programmatically create, place, and initialize the UIDatePicker object (I made mine in -(void)awakeFromNib, but you don't have to).

    Doing this fixed all of the weird bugs in my app. I hope this helps...
     

Share This Page