在UITextField 和 UITextView ,如何監(jiān)聽到刪除鍵。
我看到網(wǎng)上都是用代理監(jiān)聽的,我覺得不靠譜。
其實蘋果已經(jīng)寫的很清楚了。
就在他們實現(xiàn)的協(xié)議里面~~
NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextView : UIScrollView<UITextInput>
@protocol UITextInput<UIKeyInput>
@protocol UIKeyInput <UITextInputTraits>
- (BOOL)hasText;
- (void)insertText:(NSString *)text;
- (void)deleteBackward;
@end
寫的非常清楚,一看就明白。
-deleteBackward 這個方法就是刪除按鈕監(jiān)聽。
只要自己寫個子類,重寫此方法就能監(jiān)聽。