In addition to using the text input box to output UITextField in the project, UITextView is also used frequently. It is inevitable that there will be a need to listen to the number of text in the UITextView text box. The following two common methods are introduced in swift3.
Method 1: Global notification
1. Registration Notification
Register global notifications to listen for UITextView text changes in the appropriate location
//UITextView Two ways to start input by listening to the UITextView//Method 1: Notification(self, selector: #selector(), name: , object: nil)
2. Implement the listening method. The method is named textViewChange
@objc fileprivate func textViewChange() { XWLog("textViewChange of text :\()") }
3. In the controller, the ecstasy notification
//Remove Notificationdeinit { (self) }
Method 2: Agent
1. Set up a proxy
//1. Set up a proxy = self
2. Comply with the proxy agreement and implement the proxy method
//MARK: - TEXTVIEW DELEGATE extension ComposeVC : UITextViewDelegate { func textViewDidChange(_ textView: UITextView) { if (using: .utf8) > 0 { //There are texts in the text box that have more than 0 characters. Perform the corresponding operation}else{ //There are text numbers in the text box equal to 0 and perform the corresponding operation} } }
The above is the method (three methods) for Swift3 monitoring UITextView text changes in iOS development introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!