1

I have a UITableView containing UITextFields. I would like to be able to add new text fields by pasting text copied from another application and have the paste event create as many textFields as there are newlines in the pasted text.

For example, I have selected these lines from the Notes app:

   Alice
   Fred
   Betsy

When I paste that selection into my app via the keyboard when editing a textField I get the string "Alice Fred Betsy" with the newline characters removed. This removal must be happening deep in the keyboard before it gets to the textField. Is there some way I can intervene and make the paste into three paste events resulting in three textFields?

Thanks!

-Allan

WholeCheese
  • 437
  • 3
  • 14

1 Answers1

1

Since UITextField is forced to have only line of text, it is forced by the system not to contain new line characters ("\n"). What you can do here is to use UITextViews with disabled scrolling and break any input into lines and fill other UITextViews manually with the result.

Have a look at this answer about faking UITextField with UITextView: https://stackoverflow.com/a/37187098/1689376

Community
  • 1
  • 1
alexburtnik
  • 7,661
  • 4
  • 32
  • 70
  • 1
    Thanks, Alex. I was hoping I did not have to go the UITextView route; surely there must be a way to intercept the text before the UITextField sees it? At any rate, I guess I will need to look at using UITextView instead. – WholeCheese Oct 09 '16 at 04:47