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

Multi tool use
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
add a comment |
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
add a comment |
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
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
swift uitextfield
edited Dec 30 '18 at 12:26
Pauli
asked Dec 30 '18 at 12:11
PauliPauli
701210
701210
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
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 toisUserInteractionEnabled
, create a var namedshouldHideKeyB
and manage that like above
– Sh_Khan
Dec 30 '18 at 12:31
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 toisUserInteractionEnabled
, create a var namedshouldHideKeyB
and manage that like above
– Sh_Khan
Dec 30 '18 at 12:31
add a comment |
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
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 toisUserInteractionEnabled
, create a var namedshouldHideKeyB
and manage that like above
– Sh_Khan
Dec 30 '18 at 12:31
add a comment |
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
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
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 toisUserInteractionEnabled
, create a var namedshouldHideKeyB
and manage that like above
– Sh_Khan
Dec 30 '18 at 12:31
add a comment |
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 toisUserInteractionEnabled
, create a var namedshouldHideKeyB
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Dec 30 '18 at 15:24
hartwellalexhartwellalex
31623
31623
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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