Reputation: 247
func textFieldShouldReturn(_ textfield: UITextField) -> Bool{
p1s1TextField.resignFirstResponder()
return true
}
func textFieldShouldReturn(_ textfield: UITextField)-> Bool{
p2s1TextField.resignFirstResponder()
return true
}
So this is the code I need to write, the only difference being that they affect two different text fields. I understand I need to change the sender in order to avoid the redeclaration error but am unsure what to change it to.
Upvotes: 0
Views: 700
Reputation: 7893
Try this to use delegate method according to different Text-fields.
func textFieldShouldReturn(_ textfield: UITextField) -> Bool{
if textfield == p1s1TextField {
p1s1TextField.resignFirstResponder()
}else if textfield == p2s1TextField {
p2s1TextField.resignFirstResponder()
}
return true
}
Upvotes: 1
Reputation: 38833
Just use one of them and the parameter textfield
is your current textfield
.
So:
func textFieldShouldReturn(_ textfield: UITextField) -> Bool {
textfield.resignFirstResponder()
return true
}
Upvotes: 4