7

I am developing custom keyboard with keyboard extension in iOS8.

I can dismiss keyboard with following method.

[self dismissKeyboard];

However above method is only dismiss keyboard. I want to do it like return Method that can like GO or Search that can use both dismiss and Go Event like iOS Built in Keyboard.

How can i do it?

Fire Fist
  • 7,032
  • 12
  • 63
  • 109
  • 2
    @Alec Yes. You can use [self.textDocumentProxy insertText:@"\n"];. \n will automatically do above functions. – Fire Fist Jul 23 '14 at 05:25

3 Answers3

11

You can use [self.textDocumentProxy insertText:@"\n"];

woof
  • 1,288
  • 1
  • 11
  • 13
-2

just call [self dismissKeyboard], self is UIinputViewController instance

fairzy
  • 37
  • 6
-3

Great question

First of all, reacting to the "GO" or "SEARCH" return key presses is your responsibility. Meaning that when the user clicks on "GO" - in your app, you need to catch that event, and implement whatever you want there (probably search something..). Meaning that you can take that implementation and just push it before dismissing the keyboard.

EDIT:

First this is how to respond to return key clicks in your app:

conform to the text field delegate:

@interface MyViewController : UIViewController <UITextFieldDelegate>

and then override this method with your implementation - what do you want to do when the user clicks the return key? (or go or search etc..):

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
   // your implementation
    return YES;
}

This is how you respond to clicks on the return key and implement whatever you want when it's clicked.

notice that you can change the traits of the button to GO and SEARCH using

theTextField.returnKeyType = UIReturnKeySearch;

Notice that YOUR implementation is what matters in the whole deal here - and you can just embed this implementation right before dismissing the keyboard

Thanks and good luck!

nurnachman
  • 4,468
  • 2
  • 37
  • 40
  • I don't know how to do like you said. – Fire Fist Jun 30 '14 at 05:07
  • OP was talking about Keyboard Extension, you don't have a `UITextField` except in the host app. @woof answer works well as other apps's textField delegate is calling `textFieldShouldReturn` upon a `\n` insertion (via `- (void)insertText:(NSString *)text`) – bauerMusic Aug 10 '14 at 15:22