Adding TabGestureRecognizer to TextField
All my UiTextFields are created programmatically so i can't just right-click-pull-over the onTab function to the swift file.
I tried to add a gesture recognizer to the text field, but now I have to DOUBLE-click so clickTextField() is triggered.
// make clickable
let clickName = MyTapGesture(target: self, action: #selector(ViewMain.clickTextField(_:)))
clickName.count_of_selection = String(i)
self.finishName[i].addGestureRecognizer(clickName)
How can I make it so that this works with one click. A different approach maybe?
swift uitextfield
add a comment |
All my UiTextFields are created programmatically so i can't just right-click-pull-over the onTab function to the swift file.
I tried to add a gesture recognizer to the text field, but now I have to DOUBLE-click so clickTextField() is triggered.
// make clickable
let clickName = MyTapGesture(target: self, action: #selector(ViewMain.clickTextField(_:)))
clickName.count_of_selection = String(i)
self.finishName[i].addGestureRecognizer(clickName)
How can I make it so that this works with one click. A different approach maybe?
swift uitextfield
add a comment |
All my UiTextFields are created programmatically so i can't just right-click-pull-over the onTab function to the swift file.
I tried to add a gesture recognizer to the text field, but now I have to DOUBLE-click so clickTextField() is triggered.
// make clickable
let clickName = MyTapGesture(target: self, action: #selector(ViewMain.clickTextField(_:)))
clickName.count_of_selection = String(i)
self.finishName[i].addGestureRecognizer(clickName)
How can I make it so that this works with one click. A different approach maybe?
swift uitextfield
All my UiTextFields are created programmatically so i can't just right-click-pull-over the onTab function to the swift file.
I tried to add a gesture recognizer to the text field, but now I have to DOUBLE-click so clickTextField() is triggered.
// make clickable
let clickName = MyTapGesture(target: self, action: #selector(ViewMain.clickTextField(_:)))
clickName.count_of_selection = String(i)
self.finishName[i].addGestureRecognizer(clickName)
How can I make it so that this works with one click. A different approach maybe?
swift uitextfield
swift uitextfield
edited Nov 23 '18 at 11:05
wvteijlingen
8,74112545
8,74112545
asked Nov 20 '18 at 19:43
Martin VidicMartin Vidic
1631110
1631110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
UITextField has a tap gesture. You need to use it's delegate methods:
func textFieldShouldBeginEditing(_ textField: UITextField)
func textFieldDidEndEditing(_ textField: UITextField)
func textFieldShouldEndEditing(_ textField: UITextField)
func textFieldDidBeginEditing(_ textField: UITextField)
func textFielShouldClear(_ textField: UITextField)
func textFielShouldReturn(_ textField: UITextField)
Do not forget
yourTextField.delegate = self
after you create an extension for you vc:
extension ViewController: UITextFieldDelegate {
// here you add the necessary delegate methods for your textFields
}
Note: You do not need to implement every method. Use only the one you need. More details can be found on AppleDeleveloper .
add a comment |
try setting a tag value to each UITextField to be able to deferenciate between them.
For example :
var iter = 0 //Defaults auto-incrementation
let textField = UITextField()
textField.frame = CGRect(x: 20, y: y, width: Int(UIScreen.main.bounds.width-40), height:50)
textField.placeholder = title + " :"
//Setting the tag
textField.tag = iter
//Setting the controller as delegate to UITextField
textField.delegate = self
//AddSubview
self.view.addSubview(textField)
//Auto-incrementation
iter += 1
You need also to make use of UITextField delegate methods :
//TODO: Declare textFieldDidBeginEdditing here :
func textFieldDidBeginEditing(_ activeTextField: UITextField) {
//Code
}
//TODO: Declare textFieldDidEndEditing here :
func textFieldDidEndEditing(_ activeTextField: UITextField) {
//Code
}
it depends on your needs you can use more or less methods. Good Luck.
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%2f53400439%2fadding-tabgesturerecognizer-to-textfield%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
UITextField has a tap gesture. You need to use it's delegate methods:
func textFieldShouldBeginEditing(_ textField: UITextField)
func textFieldDidEndEditing(_ textField: UITextField)
func textFieldShouldEndEditing(_ textField: UITextField)
func textFieldDidBeginEditing(_ textField: UITextField)
func textFielShouldClear(_ textField: UITextField)
func textFielShouldReturn(_ textField: UITextField)
Do not forget
yourTextField.delegate = self
after you create an extension for you vc:
extension ViewController: UITextFieldDelegate {
// here you add the necessary delegate methods for your textFields
}
Note: You do not need to implement every method. Use only the one you need. More details can be found on AppleDeleveloper .
add a comment |
UITextField has a tap gesture. You need to use it's delegate methods:
func textFieldShouldBeginEditing(_ textField: UITextField)
func textFieldDidEndEditing(_ textField: UITextField)
func textFieldShouldEndEditing(_ textField: UITextField)
func textFieldDidBeginEditing(_ textField: UITextField)
func textFielShouldClear(_ textField: UITextField)
func textFielShouldReturn(_ textField: UITextField)
Do not forget
yourTextField.delegate = self
after you create an extension for you vc:
extension ViewController: UITextFieldDelegate {
// here you add the necessary delegate methods for your textFields
}
Note: You do not need to implement every method. Use only the one you need. More details can be found on AppleDeleveloper .
add a comment |
UITextField has a tap gesture. You need to use it's delegate methods:
func textFieldShouldBeginEditing(_ textField: UITextField)
func textFieldDidEndEditing(_ textField: UITextField)
func textFieldShouldEndEditing(_ textField: UITextField)
func textFieldDidBeginEditing(_ textField: UITextField)
func textFielShouldClear(_ textField: UITextField)
func textFielShouldReturn(_ textField: UITextField)
Do not forget
yourTextField.delegate = self
after you create an extension for you vc:
extension ViewController: UITextFieldDelegate {
// here you add the necessary delegate methods for your textFields
}
Note: You do not need to implement every method. Use only the one you need. More details can be found on AppleDeleveloper .
UITextField has a tap gesture. You need to use it's delegate methods:
func textFieldShouldBeginEditing(_ textField: UITextField)
func textFieldDidEndEditing(_ textField: UITextField)
func textFieldShouldEndEditing(_ textField: UITextField)
func textFieldDidBeginEditing(_ textField: UITextField)
func textFielShouldClear(_ textField: UITextField)
func textFielShouldReturn(_ textField: UITextField)
Do not forget
yourTextField.delegate = self
after you create an extension for you vc:
extension ViewController: UITextFieldDelegate {
// here you add the necessary delegate methods for your textFields
}
Note: You do not need to implement every method. Use only the one you need. More details can be found on AppleDeleveloper .
edited Nov 20 '18 at 20:03
answered Nov 20 '18 at 19:54
Deryck LucianDeryck Lucian
1558
1558
add a comment |
add a comment |
try setting a tag value to each UITextField to be able to deferenciate between them.
For example :
var iter = 0 //Defaults auto-incrementation
let textField = UITextField()
textField.frame = CGRect(x: 20, y: y, width: Int(UIScreen.main.bounds.width-40), height:50)
textField.placeholder = title + " :"
//Setting the tag
textField.tag = iter
//Setting the controller as delegate to UITextField
textField.delegate = self
//AddSubview
self.view.addSubview(textField)
//Auto-incrementation
iter += 1
You need also to make use of UITextField delegate methods :
//TODO: Declare textFieldDidBeginEdditing here :
func textFieldDidBeginEditing(_ activeTextField: UITextField) {
//Code
}
//TODO: Declare textFieldDidEndEditing here :
func textFieldDidEndEditing(_ activeTextField: UITextField) {
//Code
}
it depends on your needs you can use more or less methods. Good Luck.
add a comment |
try setting a tag value to each UITextField to be able to deferenciate between them.
For example :
var iter = 0 //Defaults auto-incrementation
let textField = UITextField()
textField.frame = CGRect(x: 20, y: y, width: Int(UIScreen.main.bounds.width-40), height:50)
textField.placeholder = title + " :"
//Setting the tag
textField.tag = iter
//Setting the controller as delegate to UITextField
textField.delegate = self
//AddSubview
self.view.addSubview(textField)
//Auto-incrementation
iter += 1
You need also to make use of UITextField delegate methods :
//TODO: Declare textFieldDidBeginEdditing here :
func textFieldDidBeginEditing(_ activeTextField: UITextField) {
//Code
}
//TODO: Declare textFieldDidEndEditing here :
func textFieldDidEndEditing(_ activeTextField: UITextField) {
//Code
}
it depends on your needs you can use more or less methods. Good Luck.
add a comment |
try setting a tag value to each UITextField to be able to deferenciate between them.
For example :
var iter = 0 //Defaults auto-incrementation
let textField = UITextField()
textField.frame = CGRect(x: 20, y: y, width: Int(UIScreen.main.bounds.width-40), height:50)
textField.placeholder = title + " :"
//Setting the tag
textField.tag = iter
//Setting the controller as delegate to UITextField
textField.delegate = self
//AddSubview
self.view.addSubview(textField)
//Auto-incrementation
iter += 1
You need also to make use of UITextField delegate methods :
//TODO: Declare textFieldDidBeginEdditing here :
func textFieldDidBeginEditing(_ activeTextField: UITextField) {
//Code
}
//TODO: Declare textFieldDidEndEditing here :
func textFieldDidEndEditing(_ activeTextField: UITextField) {
//Code
}
it depends on your needs you can use more or less methods. Good Luck.
try setting a tag value to each UITextField to be able to deferenciate between them.
For example :
var iter = 0 //Defaults auto-incrementation
let textField = UITextField()
textField.frame = CGRect(x: 20, y: y, width: Int(UIScreen.main.bounds.width-40), height:50)
textField.placeholder = title + " :"
//Setting the tag
textField.tag = iter
//Setting the controller as delegate to UITextField
textField.delegate = self
//AddSubview
self.view.addSubview(textField)
//Auto-incrementation
iter += 1
You need also to make use of UITextField delegate methods :
//TODO: Declare textFieldDidBeginEdditing here :
func textFieldDidBeginEditing(_ activeTextField: UITextField) {
//Code
}
//TODO: Declare textFieldDidEndEditing here :
func textFieldDidEndEditing(_ activeTextField: UITextField) {
//Code
}
it depends on your needs you can use more or less methods. Good Luck.
answered Nov 21 '18 at 7:48
YD-YD-
18618
18618
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%2f53400439%2fadding-tabgesturerecognizer-to-textfield%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