How to track "Hide keyboard" button on iPad in searchBar? - ios

I have searchBar and tableView. I have a bug, when user clicks on "hide keyboard". I have tried to user Notification Center for hiding keyboard. But it also works for "cancel" button. Maybe there is a way to exclude determining "cancel button"?

On hide keyboard button click listener you can use two from the below options
1) self.view.endEditing(true)
This will notify your current active view to stop editing which will
automatically hides the keyboard
2) yourTextField.resignFirstResponder
This will stop focusing your current editing textView which will
automatically hide the keyboard.
As you will write this code specific to your Hide keyboard button it won't apply the same solution to your Cancel button.

Related

UITextField iOS: how to deal with the dismiss keyboard button?

On the iPhone in Landscape orientation, there is a button in the lower right corner that causes the keyboard to dismiss. I really don't want this button to be there, since I have a Done button already and users should only be able to stop editing the textfield by pressing this Done button (which has to be there to address portrait orientation anyway).
I'm wondering if there's a way to remove that keyboard dismissal button, or if not, I'd appreciate any suggestions for UITextField delegate behavior that differentiates between proper dismissal (Done button pressed) and improper (first responder might resign even though Done button not pressed, e.g. because of aforementioned problem button or view controller dismissal).
One thing you can do is declare a variable, something like, isDismissedProperly and initiate it to false. Then subscribe to keyboard show and hide notifications. UIKeyboardDidShowNotification and UIKeyboardDidHideNotification. In the target method for done button(as mentioned in the question), change the isDismissedProperly to true. And in the keyboardDidHide method, you can check if isDismissedProperly is true or false.
If it's true, then user dismissed the keyboard by pressing done button.
Hope it helps!

What is the correct approach for dismissing the keyboard when using a UITextView?

I am wondering what the best approach for dismissing a keyboard is when using a UITextView. At the minute for UITextFields I dismiss the keyboard when the return button is pressed. However for the TextView I want to have the return button actually add new lines so there is no additional buttons remaining to close.
What if any is the current "standard" approach for dealing with this issue? For example is it to add an additional button on the screen or is there another approach?
Thanks
On the iPad there is a "dismiss" button on the keyboard. For iPhones, add an inputAccessoryView to the UITextView. Put a "dismiss" button there.
If you have several fields (text fields, text views, etc.) in some sort of form, you could have a standard inputAccessoryView for all of them. Include a "Next" button (to go to the next field) and a "Done" button (to dismiss the keyboard).

Cancel button on UISearchController is not working sometimes

I am facing an issue with the UISearchController in iOS 8. The problem is that whenever I am clicking on cancel button, instead of cancelling the search operation, it is bringing up the keyboard.
Follow below steps to reproduce the issue -
Click on the search bar.
Type a word and click on search(This will
dismiss the keyboard)
Now click on cancel.
Now, instead of dismissing the search, the keyboard is popping up for entering the text. This usually happens when I am tapping at the right half of cancel button and it can be reproduced even in standard iOS apps like Contacts app. I would like to dismiss search when cancel is tapped.
Is there any workaround for this issue?
You could remove the search bar as a first responder programatically when the cancel button is clicked which will prevent the keyboard from coming up.
[searchController.textField resignFirstResponder];

Custom Button as a Navigation Button

I have a custom button like facebook app does. When I click on custom button while editing my textview, it shows left menu but doesn't hide keyboard.
I have tried everything but still my problem is there. How I can hide keyboard on clicking on custom button.
Just include this in the burger's button IBAction
[self.view endEditing:YES];

How to send open uikeyboard back while opening other subview?

In my application I have one uiview.
I am adding another subview to this view which contains one textfield.
when user clicks that field then it display the keypad.
This subview also contains one add and delete button.
when user clicks on that button another view is opened which is also the subview of main view and that view contains selection list in the table.
The problem here is when user types something in textfield so keyboard is open.
if user does not dismiss that keyboard and clicks on add button to select from selection list then only half of the selection list is visible because keyboard is still open.
I want to send the keyboard back.
Here i do not want to dismiss the keyborad.while user clicks the add button.i only want to send it back to the selection view.when user is done with selection view keyboard should be open as it is.How can i solve this issue?
If you want the keyboard to go away, you need to dismiss it when they click on the button by using [yourTextField resignFirstResponder];.
If you want it to come back when they select an item, you will need to call [yourTextField becomeFirstResponder];.

Resources