Dismiss a number pad-style keyboard without adding Done key - objective-c

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.

Related

How to suppress virtual Keyboard slide-in animation?

I've got a problem with creating a modal search view that emulates the behaviour of that of the Weather app. Specifically, there are two animations, that are bothering me and introduce unneeded 0.2 s delays:
When the modal view becomes visible, I give focus to the UISearchDisplayController.searchBar by caling becomeFirstResponder in viewDidAppear. However, the keyboard is not visible, when the modal view has slid in, but needs another 0.2s to slide in after the animation of tehe modal view transition is complete. Moving the call to another callback like viewWillAppear or viewDidLoad did no good, the keyboard won't show up in the first place.
When the user touches cancel, there is another animation taking place, before the delegate's searchDisplayControllerDidEndSearch method is called, expanding the search text field and "melting" away the button. Again, this animation is unneded as the modal view is supposed to transition out when the button is touched.
Additionally, when I dismiss and re-present the same view, not only does the keyboard slide in after the transition, but the cancel button does the same (luckily simultaneously).
I am aware of a similar problem described here: Keyboard Animation Issues When Calling becomeFirstResponder within a Modal View Controller.
However, it seems like the behaviour of the search bar is sligtly differet then that of text field. I could not reproduce the steps described by that author to make the keyboard visible by calling becomeFirstResponder in viewDidLoad.
Regards,
Chris
I think I found your answer. When you add a search bar using the interface builder, you can do it two ways: "Search bar" and "Search bar and Search Display Controller".
I was using the second and was having the very same problem you described. I could only invoke the keyboard (using becomeFirstResponder) on "viewDidAppear". But if you do it adding just the search bar it works. Now I can call becomeFirstResponder on "viewDidLoad" and the keyboard appears together with the view itself.
I means a little more work, but really not much. You have to set your controller to be the delegate of the search bar. I added a list view for the results and made my controller become its delegate and its datasource.

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.

UITextfield in UITableViewCell resign FirstResnponder

I have a UITextfield of type NumberPad in a UITableViewCell. How can I make it resign first responder (i.e. dismiss the keyboard)?
Thanks
You have to add a UIButton somewhere in your interface. I often do it on the navigation bar and then resign first responder when it is pressed.
There are all sorts of kludges to superimpose fake done buttons over the numberpad, but they are asking for trouble IMHO. It would be nice if Apple addressed this in future though as lots of people have the same issue.
Good discussion and other solutions here;
How to show "Done" button on iPhone number pad
Implement UITextFieldDelegate and set your UITextField delegate to it. In the -(BOOL)textFieldShouldReturn:(UITextField *)textField delegate method you set the resignFirstResponder call.
You can also set up an action to a button on the pad. You can do this by trying to add a done button to the pad. I know that in the most recent sdk this is somewhat impossible.
For those cases you have two options:
1.Add a done button somewhere on the view. If you are using a navigation controller you can add it to the navigation bar and simply set up the action for that button and in the action you resignFirstResponder for the UITextField.
2.Add your keyboard to a UIActionSheet and add the done button right on top of the keyboard.

How do I enable the done key and the return key in ipad objective c

Is it possible to enable or show both the "return" and "done" button on the ipad keyboard? If so, How or how to work around?
I have a UITextField that is multi-line and want to add a done button to the key board.
I dont think the keyboard can display both without augmenting the layout manually - Additionally this is not app store safe.
I have done this before by hooking the
-(void)textFieldDidBeginEditing:(UITextField *)_tf
In the UITextFieldDelegate. Although there might be a better keyboard based event to use. If your interested i will post the code.
On this event, A small toolbar appeared flush with the top of the keyboard containing next, previous and Done.
I delegated the button events from the toolbar back to the ViewController that was responsible for the TextField

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

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.