Swift3 listens for Uitextview text changes in IOS development (three methods) _ios

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.