我的单元格中有 textView,有时在 tableView 滚动期间会发生一些奇怪的调用。系统让我的 textView 成为第一响应者。我发现这些调用会产生不良行为:
#0 -[UITextView canBecomeFirstResponder] ()
#1 -[UIView(Hierarchy) deferredBecomeFirstResponder] ()
#2 -[UIView(Hierarchy) _promoteDescendantToFirstResponderIfNecessary] ()
我不知道为什么要调用这些,所以我尝试通过扩展UITextView
和覆盖来解决这个问题- canBecomeFirstResponder
。
这是我的.h:
#import <UIKit/UIKit.h>
@protocol TextViewDelegate;
@interface TextView : UITextView
@property (nonatomic, assign) id<TextViewDelegate> delegate;
@end
@protocol TextViewDelegate <UITextViewDelegate>
- (BOOL)canBecomeFirstResponder:(TextView *)textView;
@end
和.m:
#import "TextView.h"
@implementation TextView
@synthesize delegate;
- (BOOL)canBecomeFirstResponder
{
return [self.delegate respondsToSelector:@selector(canBecomeFirstResponder:)] ? [self.delegate canBecomeFirstResponder:self] : NO;
}
@end
该解决方案有效,但在线上@property (nonatomic, assign) id<TextViewDelegate> delegate;
我收到了警告,但我不知道为什么。它说Property type 'id<TextViewDelegate>' is incompatible with type 'id<UITextViewDelegate>' inherited from 'UITextView'
。
那么,如果我不这样做,为什么系统要让 textView 成为第一响应者呢?为什么我会收到此警告?有比我更好的解决方案吗?