I have textView in my cell and sometimes during tableView scroll some weird calls happen. System make my textView first responder. I’ve found these calls do unwanted behavior:
#0 -[UITextView canBecomeFirstResponder] ()
#1 -[UIView(Hierarchy) deferredBecomeFirstResponder] ()
#2 -[UIView(Hierarchy) _promoteDescendantToFirstResponderIfNecessary] ()
I can’t find out why are these called, so I’ve tried to deal with this by extending UITextView and overriding - 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 on the line @property (nonatomic, assign) id<TextViewDelegate> delegate; I’ve got warning and I don’t know why. It says Property type 'id<TextViewDelegate>' is incompatible with type 'id<UITextViewDelegate>' inherited from 'UITextView'.
So why system want to make textView first responder if I do not? Why I’m getting this warning? Is there better solution than mine?
I’m not sure , but I suspect the warning is because the pre-compiler knows about
TextViewDelegatebut it does not know yet that this protocol is inheritingUITextViewprotocol. Just declare it above like this:But I’m not sure I understand the question.
You have a table and in one/more/each cell you have an
UITextView, correct?Do you want the text view to be editable?
Because you can simply set
[textView setEditable:FALSE];Hope this helps.
Regards,
George