Reputation: 303
I want to hide the keyboard when i press any key other than the return key . For example when the user presses the character 'n' on keyboard , keyboard should disappear. Please provide me a suitable answer as soon as possible. Thanks in advance.
Upvotes: 0
Views: 816
Reputation: 119242
The keyboard hides when the text field resigns first responder. The textfield delegate is told when a key is pressed (textField:shouldChangeCharactersInRange:replacementString:
). If you need any more detail than that, please put a bit more effort into your question and show us what you have tried so far.
Upvotes: 0
Reputation: 8538
You may try UIKeyInput protocol. To catch a insert with insertText http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html
Have you used protocols?
EDIT: Then you can use method [textField resignFirstResponder];
To hide the keyboard
EDIT2: Protocols In short, the interface for class that you want to respond to the protocol must be declare as (in YourClass.h):
@interface YourClass:NSObject<UIKitInput>
then, you have to implements the protocol methods in YourClass.m:
#pragma mark -
#pragma mark UIKeyInput Protocol Methods
- (BOOL)hasText {
.....
return NO;
}
- (void)insertText:(NSString *)theText {
...;
}
- (void)deleteBackward {
....
}
Good Luck!
Upvotes: 1
Reputation: 8501
For that, you have to create a custom keyboard or you have to override the Keyboard methods. But you cannot override. Because You do not know, in which method and what code is to sense that key pressing in that frameworks. So better write a custom keyboard anyway.
Upvotes: 0