简体   繁体   中英

iOS 9 Swift 2.0 UITextFieldDidChange

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?

you can use the below coding and you can follow blow description

UITextField and dragging the "Editing Changed" send event to your subclass unit.

UITextField更改事件

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM