iOS swift delegate with more than 1 uitextfield in a uiview -
i have ios app, 1 uiview
, 3 uitextfield
(more 1) understand best practices class viewcontroller manage uitextfield
.
- class mainviewcontroller: uiviewcontroller, uitextfielddelegate ?
i wonder that, because have more 1 uitextfield
, 1 func textfield(textfield: uitextfield, shouldchangecharactersinrange range: nsrange, replacementstring string: string) -> bool
easiest way know text field use in delegate methods. i.e. have 3 text fields: field1, field2, field3 , when delegate called can detect do:
func textfield(textfield: uitextfield, shouldchangecharactersinrange range: nsrange, replacementstring string: string) -> bool { if textfield == field1 { // } else if textfield == field2 { // } else if textfield == field3 { // } return true }
do not forget make field's delegate self: field1.delegate = self
etc.
in case work fine.
if want know better solution if have more fields (10, 20?) let me know , i'll update answer.
Comments
Post a Comment