Whats the best way to have a UIView for a popup Keyboard in a UIViewController? - objective-c

I'm currently developing an iPhone application and part of it has a custom keyboard which pops up, this currently consists of
UIViewController
(1) UIButton (to activate keyboard)
UIView
-- 10 x Input buttons (part of the keyboard)
When the app starts I set the UIView to be out of view, and when the button (1) is clicked the UIView animates up from the bottom of the screen, this works perfectly but it got me thinking "Is this really the best way to do this?".
It would be nice if I could have my custom keyboard separate to the UIViewController so that in future apps I could just include the files which build up the UIView / Keyboard.
Any advice would be much appreciated.

Is inputAccessoryView what you're looking for?
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.

Related

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.

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.

UISearchDisplayController not displaying keyboard when text area touched

I have a UITableView in a controller that is nested under a UITabBar.
The interaction is all wired up in Interface Builder so far, nothing done programmatically in terms of view switching.
I've added a UISearchDisplayController as the header of my UITableView. It displays fine, and when I tap on the text entry area, the cancel button appears and the black overlay flies in.
However, the keyboard never appears and when tapping the cancel button, the overlay flies out and the cancel button disappears, but the text entry area keeps focus and the caret stays flashing there, so I cannot tap there again to re-display the search results.
So essentially I have two problems:
Keyboard not appearing when starting to edit text on UISearchBar from UISearchDisplayController
UISearchBar not loosing focus when cancel button is tapped.
What am I doing wrong?
The .xib file that had my tab bar in it contained a UIWindow.
This lead to all sorts of craziness and in the end I gave up on trying to do this with interface builder, and resorted to constructing the UITabBar in code, thereby not creating a second UIWindow.
This resolved the problems and the UISearchDisplayController behaved correctly.
check this method in UISearchBarDelegate:
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar;
Try to see if this is getting called and do keyboard-related removal in here. If not, try making another UISearchDisplayController. (I actually never use the default viewController's one). Also, make sure the delegate is correctly set.

Getting UIPicker to appear when user selects a UITextField

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.

Dismiss a number pad-style keyboard without adding Done key

There is no Done button on a Number Pad-type keyboard. I don't want to add a custom Done button, but how do I dismiss the keyboard?
You could add a UINavigationBar/UIToolBar with a done button(a UIBarButtonItem), and make the textField/textView resignFirstResponder on the done button's action.
You can add the UINavigationBar/UIToolBar as inputAccessoryView of textField/textView.
textField.inputAccessoryView = aNavBarWithDoneButton;
Edit: Availability iOS (3.2 and later)
The simplest solution is to add a new button somewhere in your UI that calls resignFirstResponder on your UITextField (or whatever) when tapped. Putting this in a toolbar is problematic on iPhone because toolbars are typically at the bottom of the screen and obscured by the keyboard.
A slightly more complex solution is to put an invisible UIView behind all of your other tappable UI elements. Any taps not handled by your existing UI will go to this new view, which can call resignFirstResponder on your text field.
If neither of these sound appealing, perhaps you should expand your question to include the type of behavior you want.