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?
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.
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.
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.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With