UiDatePicker displays but not UIPickerView - iphone

If I drop a UIDatePicker onto a UIView in IB and run the app, the date picker displays. If I delete the date picker, drop a UIPickerView onto the same UIView and run the app, the UIPickerView doesn't display. What is the difference?

I believe the issue might be that the UIPicker has nothing to pick from.
The UIpicker lets the user select an item from a list.
You need to supply some options for the user to pick from such as a list of colors where as the datepicker lets the user pick a date and it doesnt need the dev to provide a list of things to pick from.

Related

Custom UIPickerView to have unselectable first row

I'd like to create a custom UIPickerView in iOS that will present the elements of the picker to the user, but have a "blank" selection at the top. If the user doesn't select anything then the result from the UIPickerView is nil. If the user scrolls down to select something, then it just returns to proper index in the list.
The problem with the UIPickerView is that when you come into it, it looks like the user has at least selected the first element.
I would like to "force" the user to pick something.
Thanks for your help.
can't you just make the first item in the datasource a #""?

Date Picker And Table View

I'm working on a project on iPhone and I want a Date Picker on a few of the rows in the table view.
Please help me out.
If this is a StaticCell TablieView, then you can just add these via storyboard.
If not, you will need to use the cellForRowAtIndexPath to determine which cell you want to add the datepicker to. You would then instantiate a UIDatePicker, set the attributes if needed and add that subview to your cell.
One warning - using something this large in an iPhone TableView app will result in a crappy user experience.

Is it possible to 're-skin' the IOS Date Picker?

I require a custom date picker, essentially just want to remove the graphics in the IOS version but retain the 3 column date scroll. Does it need to be re-built from scratch (all research points to yes) , or is it possible to just disable or swap the images.
I haven't tried it myself, but maybe you could just add a UIImageView above the datepicker with a transparent section for the scrolling sections to show through.
Change UIPickerView background check adam's answer there relating to picker views.
I have altered those before for a picker, so the datepicker might be similar.
I don't think you can change the images of a UIDatePicker. UIPickerView you can, but as you say, you would lose a lot of functionality.

UIPickerView row selection

I have a UIPickerView with two components.
It works fine when the user scrolls each component until it reaches the desired value.
But I want it to behave like the picker in the calendar or the clock apps. Meaning: When the user presses a certain value in one of the components, I want that component to automatically turn that row to be the selected row (so the user doesn't always have to scroll, he/she can also simply select the value they want).
Does anyone know how to do that?
Thank you,
~Chonch
It is standard picker behaviour and it should work so automatically.
If your picker does not select tapped row automatically try to set userInteractionEnabled property to NO for the view you return from viewForRow: method in picker data source.

How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user's birthday.
I'd like to have it so that when the user selects the birthday field, a view containing a UIDatePicker would come up as, just like the different keyboards do when selecting a text field.
Can this be done? I would have to prevent the text field from being the first responder (to avoid having the keyboard come up) and I would have to animate the view sliding up if no keyboard was showing before.
Would presenting the view modally be an option? If so how would I go about doing it? From the documentation it seems that modal views still take up the whole screen, I just want to use the lower 216 pixels (height of the keyboard and UIDatePicker).
Any one have any tips on how to go about doing this?
Old question but the correct way to do this these days would be to set the UITextField's inputView to a picker you created somewhere. Something like this:
UIPickerView *myPicker = [[UIPickerView alloc] init];
// set picker frame, options, etc...
// N.B. origin for the picker's frame should be 0,0
[myTextField setInputView:myPicker];
When you go to edit a UITextField, iOS really just displays whatever view is at textField.inputView which by default is the keyboard, you can make it anything you want as long as it's a subclass of UIView.
Regarding animation, take a look at DateCell sample application -
http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html
And in any case, the proper way to do this is set UITextField's inputView to show the picker instead of the keyboard. That's what it's meant to do. More on that here:
How can I present a picker view just like the keyboard does?
Cheers,
Oded.
I would implement this by just animating a view containing the UIDatePicker, a Done, and Cancel button) up from the bottom of the screen. Using CoreAnimation, this should be pretty easy.
Why are you using a text field if you don't want to accept user input from a keyboard? Instead use a UILabel subclass (where you override the touchesBegan/Ended:withEvent: set of methods to show the UIDatePicker) or a UIButton (where your action is a method which slides up the UIDatePicker).