4 Replies
      Latest reply on Jan 16, 2020 2:57 PM by Claude31
      imsmooth Level 1 Level 1 (0 points)

        I read data from a file and append it to a textView. I can then bring up the keyboard to edit the data. I save the data when exiting. If I used [self.myTextView resignFirstResponder] to remove the keybard and then come back to the textView I can no longer access the textView field. If I comment out the [self.myTextView resignFirstResponder] the keyboard never goes away, but the data is properly written to the textView field.

         

        Any ideas why the resignFirstResponder is causing an issue?

        • Re: textView not working correctly
          Claude31 Level 8 Level 8 (7,895 points)

          Could you show the complete code ? When do you call resign ? When you type return ? When tapping a Done button ?

           

          What do you mean "I can no longer access the textView field."

          Do you mean the keyboard will not show anymore ?

           

          Is it in simulator or on device ?

            • Re: textView not working correctly
              imsmooth Level 1 Level 1 (0 points)

              I realize how confusing my question sounds. I need to rethink this and find what code I can present.

                • Re: textView not working correctly
                  Claude31 Level 8 Level 8 (7,895 points)

                  I tested this (Swift) and works OK:

                   

                  class ThirdViewController: UIViewController, UITextViewDelegate {
                  
                      @IBOutlet weak var textView: UITextView!
                     
                      override func viewDidLoad() {
                          super.viewDidLoad()
                  
                          // Do any additional setup after loading the view.
                      }
                     
                      func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
                         
                          if text == "\n" {
                              textView.resignFirstResponder()
                          }
                          return text != "\n"
                      }
                  
                  }