Return Key method in UIInputViewController in iOS8?
Asked Answered
B

3

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?

Bereniceberenson answered 23/6, 2014 at 12:19 Comment(1)
@Alec Yes. You can use [self.textDocumentProxy insertText:@"\n"];. \n will automatically do above functions.Bereniceberenson
S
11

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

Solitta answered 27/6, 2014 at 7:23 Comment(1)
This is not working for me. It just go to the new line!Suint
F
-2

just call [self dismissKeyboard], self is UIinputViewController instance

Fugal answered 18/9, 2014 at 8:22 Comment(0)
U
-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!

Unconditioned answered 29/6, 2014 at 21:58 Comment(2)
I don't know how to do like you said.Bereniceberenson
OP was talking about Keyboard Extension, you don't have a UITextField except in the host app. @Solitta answer works well as other apps's textField delegate is calling textFieldShouldReturn upon a \n insertion (via - (void)insertText:(NSString *)text)Lorianne

© 2022 - 2024 — McMap. All rights reserved.