Getting UIPicker to appear when user selects a UITextField - objective-c

I have a simple UITextField called month where I get users to simply enter the month they want via the keyboard that comes up. I would now like it for them to be able to use a UIPickerDate (or UIPicker) to make this selection instead. So when they press on the text field, a mini UIPicker appears and they make there selection, press anywhere on the screen and the picker disappears.
Does anyone know how to do this or has any suggestions? I am pretty new to programming and have looked at other answers but everyone seems to be referring to this being done in a table.
Thanks in advance!

You can set the inputView property on the UITextField to be an instance of UIDatePicker. When the instance of UITextField becomes the first responder, the picker view will be displayed with the standard keyboard animation.
// Assume that self.monthTextField and self.datePicker
// are properties of the view controller class
self.monthTextField.inputView = self.datePicker;
As for dismissing, that depends on the context. If there are more text fields to populate, consider adding a UIToolbar as the inputAccessoryView of self.monthTextField. Then you can add something like a UIBarButtonItem to make the next text field the first responder, similar to how the standard keyboard provides a Next button.

Related

Suppress UIPickerView from loading - Obj C

I have a UIPickerView that I created programmatically. It shows up when someone presses the UITextField on the screen. The only problem is that if someone presses the UITextField after the UIPickerView has already been populated, more and more PickerViews start layering on top of the previous one.
What is the proper way to suppress populating a UIPickerView if one is already on screen?
There are ofc. multiple ways of doing this, but the most simple would be to just keep a reference to UIPickerView. In other words just store it away in a class variable and check if it's not nil.
You could also set the tag property on the UIPickerView and by querying it's super view check if it is already there. More info on tags: http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instp/UIView/tag
Does that make sense?
You could disable your UITextField once the UIPicker appears, and re-enable it once you have dismissed the picker.

How can I create UIKeyboard with done button on top right corner?

I need to show UIKeyboard with done button on top right corner ..please look into attached image..any help would be appreciated.
This might help you. please check it out BSKeyboardControls
Create a UIToolbar keep two bar buttons in that. Initially Hide that toolbar.
Show the toolbar on the textfield didBeginEditing delegate of textfield
and hide the toolbar in didEndEditing delegate of textfield
EDIT: As prashant said BSKeyboard offers what i said. See the look and feel of it here http://www.cocoacontrols.com/platforms/ios/controls/bskeyboardcontrols
You should set inputAccessoryView propery of UITextField or UITextView to your custom view with all required buttons
#property(readwrite, retain) UIView *inputAccessoryView
Description
The custom accessory view to display when the text field becomes the
first responder The default value of this property is nil. Assigning a
view to this property causes that view to be displayed above the
standard system keyboard (or above the custom input view if one is
provided) when the text field becomes the first responder. For
example, you could use this property to attach a custom toolbar to the
keyboard.

NSDatePicker becomeFirstResponder

I have a data entry form where the first field the user wants to enter is an NSDatePicker.
I wish this field to be highlighted when the user clicks a button (labelled 'New')
I have tried putting in [myDatePicker becomeFirstResponder] but this has no effect.
Can anybody show me how to set the focus to myDatePicker?
Unfortunately, becomeFirstResponder does not work that way.
As mentioned in the docs, you should send makeFirstResponder: to the window that contains the control you wish to become the first responder. In your case the window that holds your NSDatePicker.
becomeFirstResponder can be overridden in a control to return false if you do not want it to become the first responder.
Is your picker linked to a textfield for the output? I have linked custom pickers to my textfields keyboard property before. If the output is set to the textfield, you can make the textfield the first responder and the picker will come up in place of the keyboard.

UIPicker with UITextField

I made a research and all posts here are very blury regarding this issue.
I would like to use a UIPicker when pressing on a UITextField.
I would realy appriciate a step by step guide.
I tryd all posts here but every post gives me only a portion of what I need and I can't seem to connect it all together.
This is the last part of my application and i'm going crazy to finish it..
Thank you in advanced!
Gal
There is an inputAccessoryView property that contains a view that will appear instead of a keyboard on the bottom of the screen. Create a UIPicker, adjust its frame, provide values and assign it to the inputAccessoryView property.
UIPicker will appear when user taps on your UITextField.
If you don't need editing, you may use a UILabel instead of the UITextField. Solution is the same. I have a ready-made class if you need.
Here's a way:
http://www.youtube.com/watch?v=t_F1ex5opgA&t=14m10s
-(BOOL)textfieldShouldBeginEditing:(UITextField *)textField
where textField is the name of your text field.
Call your UIPickerView and return NO so that your picker is loaded rather than the keyboard.
The idea is to call an action that opens the UIPicker when the user taps the UITextField. Because the UITextField does not responde to the usual touchUpInside events that UIButtons respond to, I would just overlay a transparent UIButton on top of the UITextField and just in case, make the text field's userInteractionEnabled property NO. Hook the UIButton to responde to touchUpInside and call a method that opens the UIPicker. Another option would be an immediate response to the text field's touch by implementing "textFieldShouldBeginEditing" and immediately resigning the text field.
The next step would be to present the UIPicker - if we are talking about iPad, this would best be done by using a UIPopoverController. On iPhone, maybe consider bringing it up modally. When you create the view controller that holds this UIPicker, be sure to add a delegate property to it so that whatever value that was selected on the picker can be transfered back to the main view controller and on to the UITextField.
Hope this helps with getting you started.

Adding an NSTextField as a subview

I'm trying to add an NSTextField as a subview of a custom view class I have (which subclasses NSView), and then make the NSTextField the first responder. This works fine. The text field shows up and I can start typing in it. However, any mouse events in the text field seem to fall through to its superview. For example, I can't see the mouse cursor when I hover over the text field, and when I click anywhere in the text field, it attempts to resign firstResponder status instead of letting me select text within the text field.
I'm not overriding hitTest or anything weird like that, and I only have one window, which is definitely the key window. Any ideas?
Thanks in advance! :-)