TextField user interaction disabled, but display an error view when touched

Multi tool use
Multi tool use












0















I have a UITextField and in my ViewController's code it is set depending on it's value to



textField.isUserInteractionEnabled = false


or



textField.isUserInteractionEnabled = true


Now, when user interaction is disabled, I would like it still to react to touches and show an error message (e.g. unhide another view), which tells the user that editing this text field is not possible.



How can I achieve this in the most lean way? This solution here (https://stackoverflow.com/a/9117285) suggests to not disable user interaction, but reject content changes - which is what I don't want (the keyboard should not show up - it won't show up when user interaction is disabled, but I can't react to touches either).










share|improve this question





























    0















    I have a UITextField and in my ViewController's code it is set depending on it's value to



    textField.isUserInteractionEnabled = false


    or



    textField.isUserInteractionEnabled = true


    Now, when user interaction is disabled, I would like it still to react to touches and show an error message (e.g. unhide another view), which tells the user that editing this text field is not possible.



    How can I achieve this in the most lean way? This solution here (https://stackoverflow.com/a/9117285) suggests to not disable user interaction, but reject content changes - which is what I don't want (the keyboard should not show up - it won't show up when user interaction is disabled, but I can't react to touches either).










    share|improve this question



























      0












      0








      0








      I have a UITextField and in my ViewController's code it is set depending on it's value to



      textField.isUserInteractionEnabled = false


      or



      textField.isUserInteractionEnabled = true


      Now, when user interaction is disabled, I would like it still to react to touches and show an error message (e.g. unhide another view), which tells the user that editing this text field is not possible.



      How can I achieve this in the most lean way? This solution here (https://stackoverflow.com/a/9117285) suggests to not disable user interaction, but reject content changes - which is what I don't want (the keyboard should not show up - it won't show up when user interaction is disabled, but I can't react to touches either).










      share|improve this question
















      I have a UITextField and in my ViewController's code it is set depending on it's value to



      textField.isUserInteractionEnabled = false


      or



      textField.isUserInteractionEnabled = true


      Now, when user interaction is disabled, I would like it still to react to touches and show an error message (e.g. unhide another view), which tells the user that editing this text field is not possible.



      How can I achieve this in the most lean way? This solution here (https://stackoverflow.com/a/9117285) suggests to not disable user interaction, but reject content changes - which is what I don't want (the keyboard should not show up - it won't show up when user interaction is disabled, but I can't react to touches either).







      swift uitextfield






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 30 '18 at 12:26







      Pauli

















      asked Dec 30 '18 at 12:11









      PauliPauli

      701210




      701210
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You either need to add a view a bove the textfield when it's disabled with a gesture to show the appropriate message , or do this



           NotificationCenter.default.addObserver(self, selector: #selector(keyShow), name:UIResponder.keyboardWillShowNotification, object: nil)

          }
          @objc func keyShow ( _ not:NSNotification) {

          if shouldHideKeyB {

          self.view.endEditing(true)

          // show disabled message
          }

          }


          where shouldHideKeyB is the current state of the textfield






          share|improve this answer


























          • That's not exactly what I am looking for. If I set isUserInteractionEnabled = false then the keyboard doesn't show up (like it is desired). However, I cannot receive touches for showing the view with the error message.

            – Pauli
            Dec 30 '18 at 12:25











          • @Pauli don't set it to isUserInteractionEnabled , create a var named shouldHideKeyB and manage that like above

            – Sh_Khan
            Dec 30 '18 at 12:31





















          0














          Instead of using isUserInteractionEnabled you could implement your own isDisabled Bool and UITextFieldDelegate and implement func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool. When isDisabled is true show the error view and return false, otherwise return true. In the didSet of isDisabled you can hide the error view.



          Returning false from this method should stop the keyboard from popping up and will still allow you to interact with the view.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53977469%2ftextfield-user-interaction-disabled-but-display-an-error-view-when-touched%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You either need to add a view a bove the textfield when it's disabled with a gesture to show the appropriate message , or do this



             NotificationCenter.default.addObserver(self, selector: #selector(keyShow), name:UIResponder.keyboardWillShowNotification, object: nil)

            }
            @objc func keyShow ( _ not:NSNotification) {

            if shouldHideKeyB {

            self.view.endEditing(true)

            // show disabled message
            }

            }


            where shouldHideKeyB is the current state of the textfield






            share|improve this answer


























            • That's not exactly what I am looking for. If I set isUserInteractionEnabled = false then the keyboard doesn't show up (like it is desired). However, I cannot receive touches for showing the view with the error message.

              – Pauli
              Dec 30 '18 at 12:25











            • @Pauli don't set it to isUserInteractionEnabled , create a var named shouldHideKeyB and manage that like above

              – Sh_Khan
              Dec 30 '18 at 12:31


















            0














            You either need to add a view a bove the textfield when it's disabled with a gesture to show the appropriate message , or do this



             NotificationCenter.default.addObserver(self, selector: #selector(keyShow), name:UIResponder.keyboardWillShowNotification, object: nil)

            }
            @objc func keyShow ( _ not:NSNotification) {

            if shouldHideKeyB {

            self.view.endEditing(true)

            // show disabled message
            }

            }


            where shouldHideKeyB is the current state of the textfield






            share|improve this answer


























            • That's not exactly what I am looking for. If I set isUserInteractionEnabled = false then the keyboard doesn't show up (like it is desired). However, I cannot receive touches for showing the view with the error message.

              – Pauli
              Dec 30 '18 at 12:25











            • @Pauli don't set it to isUserInteractionEnabled , create a var named shouldHideKeyB and manage that like above

              – Sh_Khan
              Dec 30 '18 at 12:31
















            0












            0








            0







            You either need to add a view a bove the textfield when it's disabled with a gesture to show the appropriate message , or do this



             NotificationCenter.default.addObserver(self, selector: #selector(keyShow), name:UIResponder.keyboardWillShowNotification, object: nil)

            }
            @objc func keyShow ( _ not:NSNotification) {

            if shouldHideKeyB {

            self.view.endEditing(true)

            // show disabled message
            }

            }


            where shouldHideKeyB is the current state of the textfield






            share|improve this answer















            You either need to add a view a bove the textfield when it's disabled with a gesture to show the appropriate message , or do this



             NotificationCenter.default.addObserver(self, selector: #selector(keyShow), name:UIResponder.keyboardWillShowNotification, object: nil)

            }
            @objc func keyShow ( _ not:NSNotification) {

            if shouldHideKeyB {

            self.view.endEditing(true)

            // show disabled message
            }

            }


            where shouldHideKeyB is the current state of the textfield







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 30 '18 at 12:34

























            answered Dec 30 '18 at 12:19









            Sh_KhanSh_Khan

            42k51326




            42k51326













            • That's not exactly what I am looking for. If I set isUserInteractionEnabled = false then the keyboard doesn't show up (like it is desired). However, I cannot receive touches for showing the view with the error message.

              – Pauli
              Dec 30 '18 at 12:25











            • @Pauli don't set it to isUserInteractionEnabled , create a var named shouldHideKeyB and manage that like above

              – Sh_Khan
              Dec 30 '18 at 12:31





















            • That's not exactly what I am looking for. If I set isUserInteractionEnabled = false then the keyboard doesn't show up (like it is desired). However, I cannot receive touches for showing the view with the error message.

              – Pauli
              Dec 30 '18 at 12:25











            • @Pauli don't set it to isUserInteractionEnabled , create a var named shouldHideKeyB and manage that like above

              – Sh_Khan
              Dec 30 '18 at 12:31



















            That's not exactly what I am looking for. If I set isUserInteractionEnabled = false then the keyboard doesn't show up (like it is desired). However, I cannot receive touches for showing the view with the error message.

            – Pauli
            Dec 30 '18 at 12:25





            That's not exactly what I am looking for. If I set isUserInteractionEnabled = false then the keyboard doesn't show up (like it is desired). However, I cannot receive touches for showing the view with the error message.

            – Pauli
            Dec 30 '18 at 12:25













            @Pauli don't set it to isUserInteractionEnabled , create a var named shouldHideKeyB and manage that like above

            – Sh_Khan
            Dec 30 '18 at 12:31







            @Pauli don't set it to isUserInteractionEnabled , create a var named shouldHideKeyB and manage that like above

            – Sh_Khan
            Dec 30 '18 at 12:31















            0














            Instead of using isUserInteractionEnabled you could implement your own isDisabled Bool and UITextFieldDelegate and implement func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool. When isDisabled is true show the error view and return false, otherwise return true. In the didSet of isDisabled you can hide the error view.



            Returning false from this method should stop the keyboard from popping up and will still allow you to interact with the view.






            share|improve this answer




























              0














              Instead of using isUserInteractionEnabled you could implement your own isDisabled Bool and UITextFieldDelegate and implement func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool. When isDisabled is true show the error view and return false, otherwise return true. In the didSet of isDisabled you can hide the error view.



              Returning false from this method should stop the keyboard from popping up and will still allow you to interact with the view.






              share|improve this answer


























                0












                0








                0







                Instead of using isUserInteractionEnabled you could implement your own isDisabled Bool and UITextFieldDelegate and implement func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool. When isDisabled is true show the error view and return false, otherwise return true. In the didSet of isDisabled you can hide the error view.



                Returning false from this method should stop the keyboard from popping up and will still allow you to interact with the view.






                share|improve this answer













                Instead of using isUserInteractionEnabled you could implement your own isDisabled Bool and UITextFieldDelegate and implement func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool. When isDisabled is true show the error view and return false, otherwise return true. In the didSet of isDisabled you can hide the error view.



                Returning false from this method should stop the keyboard from popping up and will still allow you to interact with the view.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 30 '18 at 15:24









                hartwellalexhartwellalex

                31623




                31623






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53977469%2ftextfield-user-interaction-disabled-but-display-an-error-view-when-touched%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    9TmWkNncqr
                    LCqhxUnn dXmOZtgtF7Vc,8KP,ufr5q2PrgEb7rC,X9exVQJZ8Jx5XGvF27eXT,upZ y3VE mx t5yW

                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas