使用委托对象这种方法处理UITextView事件,UITextView必须实现UITextViewDelegate 协议。该协议中定义了如下方法:
1.
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
——将要开始编辑该UITextView内容的时候自动激发该方法; 2.
- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
——将要结束编辑该UITextView内容的时候自动激发该方法; 3.
- (void)textViewDidBeginEditing:(UITextView *)textView;
——开始编辑时激发该方法; 4.
- (void)textViewDidEndEditing:(UITextView *)textView;
——结束编辑时激发该方法; 5.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
该UITextView内指定范围内的文本内容将要被替换时激发该方法; 6.
- (void)textViewDidChange:(UITextView *)textView;
UITextView包含的文本内容改变时激发该方法; 7.
- (void)textViewDidChangeSelection:(UITextView *)textView;
选中该UITextView控件中某些文本时会激发该方法; 8.
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
textView指定范围的内容与 URL 将要相互作用时激发该方法——该方法随着 IOS7被使用; 9.
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
textView指定范围的内容与文本附件将要相互作用时,自动激发该方法——该方法随着 IOS7被使用;