UITextView Adding new line when becoming first responder

user1940321

So i've got a UITextField that is the first responder when the page is opened (works fine). Then I've got a UITextView that is becoming the first responder when the user has pressed return and that's where my problem is. When pressing return things seem to work fine with the first responders, but the UITextView adds a line and starts the cursor blinking on the second line.. Is there anyone who may be able to help me? Thanks in advance!

Here is the switch

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    [self.fieldDescription.textView becomeFirstResponder];

    return YES;
}

See where the icon is blinking? That's where it starts when the first responders change... enter image description here

Dave G

Great question and description. I had the exact same problem.

No answer on this thread solved it for me. Someone put a link in the comments (by @AndreiRadulescu) of another thread. an answer by @rmaddy on that thread solved it. His answer was:

One solution to solve this is when you implement the textFieldShouldReturn: delegate method, be sure to return NO, and not YES. By returning NO, the newline isn't passed on to the text field.

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
// move to next field or whatever you need
[myTextView becomeFirstResponder];

return NO;
}

In Swift:

//Dismisses keyboard upon tapping the return key
func textFieldShouldReturn(textField: UITextField) -> Bool {
    txtTask.resignFirstResponder()
    return false
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

UITextView not becoming first responder in ios 7

From Java

How to prevent the keyboard from lowering when a new UITextView is assigned as first responder

From Dev

UITextView doesn't scroll to caret after becoming first responder on iOS 7

From Dev

UITextView adding new line unintentionally?

From Dev

Deadlock when changing first responder from uitextfield to uitextview [iOS 7]

From Dev

Deadlock when changing first responder from uitextfield to uitextview [iOS 7]

From Dev

iOS 8 - username UITextField secures entry when becoming first responder AFTER the password text field

From Dev

ObjC iOS11: TextField doesn't show up when becoming first responder in inputAccessoryView

From Dev

Resizing UITextView does not work correctly on first 2 characters of a new line

From Dev

No Code First option when adding new model

From Dev

UITextView becomeFirstResponder() adds new line

From Dev

When adding a line at the end of a file, the text sometimes is not written to new line

From Dev

know when NSTextField becomes first responder

From Dev

know when NSTextField becomes first responder

From Dev

Immediately change first responder when activating UITextField

From Dev

"\n" not adding new line when saving the string to text using PrintWriter

From Dev

UITextView not starting from first line in iOS

From Dev

How can I add auto indentation to UITextView when user type new line?

From Dev

Every new line add a numbered list UITextView

From Dev

NSLineBreakByTruncatingTail on UITextView removing new line breaks

From Dev

Every new line add a numbered list UITextView

From Dev

Modal view shifting when UISearchBar becomes first responder in landscape orientation

From Dev

Can a UITextField become a first responder when it's inside of a UICollectionViewCell?

From Dev

Removing character and adding new line

From Dev

Adding new line in printf() or format()

From Dev

Removing character and adding new line

From Dev

Adding new line in string in JSP

From Dev

adding a new line character to a row

From Dev

Adding a string to the end of each line but not the first line

Related Related

  1. 1

    UITextView not becoming first responder in ios 7

  2. 2

    How to prevent the keyboard from lowering when a new UITextView is assigned as first responder

  3. 3

    UITextView doesn't scroll to caret after becoming first responder on iOS 7

  4. 4

    UITextView adding new line unintentionally?

  5. 5

    Deadlock when changing first responder from uitextfield to uitextview [iOS 7]

  6. 6

    Deadlock when changing first responder from uitextfield to uitextview [iOS 7]

  7. 7

    iOS 8 - username UITextField secures entry when becoming first responder AFTER the password text field

  8. 8

    ObjC iOS11: TextField doesn't show up when becoming first responder in inputAccessoryView

  9. 9

    Resizing UITextView does not work correctly on first 2 characters of a new line

  10. 10

    No Code First option when adding new model

  11. 11

    UITextView becomeFirstResponder() adds new line

  12. 12

    When adding a line at the end of a file, the text sometimes is not written to new line

  13. 13

    know when NSTextField becomes first responder

  14. 14

    know when NSTextField becomes first responder

  15. 15

    Immediately change first responder when activating UITextField

  16. 16

    "\n" not adding new line when saving the string to text using PrintWriter

  17. 17

    UITextView not starting from first line in iOS

  18. 18

    How can I add auto indentation to UITextView when user type new line?

  19. 19

    Every new line add a numbered list UITextView

  20. 20

    NSLineBreakByTruncatingTail on UITextView removing new line breaks

  21. 21

    Every new line add a numbered list UITextView

  22. 22

    Modal view shifting when UISearchBar becomes first responder in landscape orientation

  23. 23

    Can a UITextField become a first responder when it's inside of a UICollectionViewCell?

  24. 24

    Removing character and adding new line

  25. 25

    Adding new line in printf() or format()

  26. 26

    Removing character and adding new line

  27. 27

    Adding new line in string in JSP

  28. 28

    adding a new line character to a row

  29. 29

    Adding a string to the end of each line but not the first line

HotTag

Archive