views:

618

answers:

3

Hi all,

I'm working on an iPhone app that uses Core Data. One of the view controllers allows the user to edit information about coffee, and it has a UITextField in which the user can enter one descriptive "tag" for the type of coffee.

I'd like to set up the UITextField to show the keyboard if the user clicks into the main area of the UITextField (to enter a new tag), and use a button as its rightView to display a UIPickerView that will allow the user to select from a list of known tags that have already been entered, i.e.:

---------------------------------------------
|This area should display keyboard | button |
---------------------------------------------

What I'm confused about is how to switch back and forth between the firstResponder keyboard and the UIPickerView and back again if the user clicks back and forth.

Surely someone out there has already done this, so any hints on how to set this up (or if I'm using the iPhone's UI elements correctly) would be great! Thanks!

A: 

Here's an article regarding how to customize the keyboard. Keep in mind that you can't outright declare your own instance of UIKeyboard, nor subclass it, so your only hope will be to find the keyboard view, and make your modifications from there.

sw
A: 

For the keyboard, you want to be mindful of becomeFirstResponder/resignFirstResponder in the delegate callbacks. Whatever your metaphor is for done or completion is where you should resign the responder.

David Sowsy
+1  A: 

You can keep track of your active text fields and pickers using 2 references like:

UITextField *activeField;
UIPickerView *activePicker;

Whenever a text field starts editing, you assign the activeField to point to it. Same thing for pickers. I'll also assume you already have a reference for this special text field in question.

Now, in the events handlers for the text field and picker view, you can control what happens when the text fields begins/ends editing and also when the picker view appears/disappears. If you have other text fields, then you'll need to check if the event was fired by the special text field by comparing it to our activeField.

I need to remind you though that the tagging scenario was implemented differently in the Contacts application. It's the standard way and it's also much easier for you.

ahmadabdolkader