Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Done button to the keyboard?

UPDATE:

I also tried implementing UITextViewDelegate delegate and then doing in my controller:

- (BOOL)textViewShouldEndEditing:(UITextView *)textView {     [textView resignFirstResponder];     return YES; } 

I also set the delegate of the text view to be self (controller view instance).

Clicking the Done button still inserts just a new line :(


UPDATE:

What I have done so far. I have implemented a UITextFieldDelegate by my view controller.

I have connected the text view to the view controller via outlet.

Then I did:


self.myTextView.delegate = self; 

And:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {     [textField resignFirstResponder];     return YES; } 

But when I click on Done button, it just adds a new line.

So I have a UITextView element on my scene and when a user taps it, keyboard appears and it can be edited.

However, I cannot dismiss the keyboard.

How can I add Done button to the keyboard so it can be dismissed?

like image 913
Richard Knop Avatar asked Apr 09 '12 17:04

Richard Knop


People also ask

How do I add a Done button to a number keypad in Swift?

addDoneKeyboardButton() — creates the keyboard done button using UIToolbar. Inside the toolbar, we create a UIBarButtonItem. You can name the button however you want, and you can add multiple buttons (depending on your needs). In other words, use this function to customize the toolbar.

How do I add a Done button on my keyboard in flutter?

You only need signed: true to trigger this workaround. @GiulioPretis Characters are shown but not clickable...so, it allows only Numbers & that is what required in this case. you can set decimal to false here if you want to use All characters from Standard Keyboard.

How do you dismiss a keyboard in Swift?

Via Tap Gesture This is the quickest way to implement keyboard dismissal. Just set a Tap gesture on the main View and hook that gesture with a function which calls view. endEditing . Causes the view (or one of its embedded text fields) to resign the first responder status.


1 Answers

thats quite simple :)

[textField setReturnKeyType:UIReturnKeyDone]; 

for dismissing the keyboard implement the <UITextFieldDelegate> protocol in your class, set

textfield.delegate = self; 

and use

- (void)textFieldDidEndEditing:(UITextField *)textField {     [textField resignFirstResponder]; } 

or

- (BOOL)textFieldShouldReturn:(UITextField *)textField {     [textField resignFirstResponder];     return YES; } 
like image 177
Sebastian Flückiger Avatar answered Sep 28 '22 04:09

Sebastian Flückiger