I am having a problem using the textFieldDidChange
or textFieldDidEndEditing
method in a subclass of UITextField
. I change the UITextField
's text
property in another source (object). Can this method be called?
Asked
Active
Viewed 1,488 times
1

Anbu.Karthik
- 82,064
- 23
- 174
- 143

Cody Weaver
- 4,756
- 11
- 33
- 51
1 Answers
4
you can use the below coding and you can follow blow description
UITextField and dragging the "Editing Changed" send event to your subclass unit.
or you can use the delegate method
func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool
or progrmatically
yourtextField.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingChanged)
func textFieldDidChange(textField: UITextField)
{
//your code
}
or the Notification is available in Swift 2.0
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(
self,
selector: "textFieldTextChanged:",
name:UITextFieldTextDidChangeNotification,
object: nil
)
func textFieldTextChanged(sender : AnyObject) {
// do your stuff here
}
the notification Type as
public let UITextFieldTextDidBeginEditingNotification: String public let UITextFieldTextDidEndEditingNotification: String public let UITextFieldTextDidChangeNotification: String
for more information use this link

Anbu.Karthik
- 82,064
- 23
- 174
- 143
-
I need to have `textFieldDidChange` or `textFieldDidEndEditing` called when I change the `UITextField`'s value from another object. Can that be done? – Cody Weaver Oct 13 '15 at 08:03
-
in that same class you can use ** textFieldDidEndEditing** , if you are another object send the observer you can use the ** UITextFieldTextDidChangeNotification** for – Anbu.Karthik Oct 13 '15 at 08:07