I have a textView in my cell, and sometimes some strange calls scroll around during a tableView. The system makes my text first responder. I found that these calls have unwanted behavior:
#0 -[UITextView canBecomeFirstResponder] ()
#1 -[UIView(Hierarchy) deferredBecomeFirstResponder] ()
#2 -[UIView(Hierarchy) _promoteDescendantToFirstResponderIfNecessary] ()
I can’t find out why they are called, so I tried to handle this by expanding UITextViewand redefining - canBecomeFirstResponder.
Here is my .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
And .m:
#import "TextView.h"
@implementation TextView
@synthesize delegate;
- (BOOL)canBecomeFirstResponder
{
return [self.delegate respondsToSelector:@selector(canBecomeFirstResponder:)] ? [self.delegate canBecomeFirstResponder:self] : NO;
}
@end
This solution works, but @property (nonatomic, assign) id<TextViewDelegate> delegate;I have a warning on the line and I don’t know why. He is speaking Property type 'id<TextViewDelegate>' is incompatible with type 'id<UITextViewDelegate>' inherited from 'UITextView'.
So, why does the system want to make textview the first responder if I do not? Why am I getting this warning? Is there a better solution than mine?
source
share