The use of text input box in the project will often use Uitextview outside the Uitextfield, there will be a need to monitor the number of text in the Uitextview text box. Here are two common ways to swift3
Mode one: Global notification
1. Notice of Registration
Registering a global notification of uitextview text changes in the right place
Two methods/methods for Uitextview listening for start input
: Notify
NotificationCenter.default.addObserver (self, selector: #selector ( Composevc.textviewchange), Name:NSNotification.Name.UITextViewTextDidChange, Object:nil)
2. Implement the Listener method here the method is named Textviewchange
@objc fileprivate func textviewchange () {
Xwlog (textview text change: \ (composetextview.text))
}
3. In the controller Ecstasy don't forget ecstasy notice
Remove notification
deinit {
NotificationCenter.default.removeObserver (self)
}
Mode two: Agent
1. Set Up Agent
1. Set proxy
composetextview.delegate = self
2. Comply with agent agreement, implement agent method
MARK:-TEXTVIEW DELEGATE
extension composevc:uitextviewdelegate {func
Textviewdidchange (_ TEXTVIEW: Uitextview) {
if textView.text.lengthOfBytes (using:. UTF8) > 0 {
//text box has more text than 0 to do the corresponding operation
}else{
/ text box has the number of text equal to 0 to do the appropriate operation}}
The above is a small set for you to introduce the development of iOS Swift3 monitoring Uitextview text Change method (three methods), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!