I've subclassed UITextView and want to override the shouldChangeTextInRange delegate function to handle maximum number of lines. So I have the following setup:
@interface CustomFieldView : UITextView <UITextViewDelegate>
Then in the .m I set my subclasses delegate to itself within initWithCoder as I am loading the view from IB:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
self.textContainer.lineFragmentPadding = 0;
self.textContainerInset = UIEdgeInsetsZero;
self.constraintHeight = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:0];
[self setScrollEnabled:NO];
self.delegate = self;
}
return self;
}
I am using attributed text, however, for debug reasons I am also setting the regular text incase this was causing issues:
[self setAttributedText:string];
[self setText:[string string]];
This works as expected and the text is set, however, I have a break point set in the delegate function:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
return YES;
}
But this is never called, can anyone let me know why this would be? I have not set the delegate in any of the other calling functions or IB, so I know this is being set. If I break in to the function that sets the text and po the delegate I get the following:
(lldb) po self.delegate
<CustomFieldView: 0x7fc01b099a00; baseClass = UITextView; frame = (8 79.5; 584 49); text = ' • Desired Sizes: Large '; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 9; gestureRecognizers = <NSArray: 0x7fc01a5d9000>; layer = <CALayer: 0x7fc01be06840>; contentOffset: {0, 0}; contentSize: {584, 49}>
So it's definitely been set correctly. So, can anyone see any reason as the why the delegate function wouldn't be called? I have also tried the - (void)textViewDidChange:(UITextView *)textView function which isn't called either.
Any guidance on how to override / implement the delegate functions from a subclass is much appreciated.
Thanks, Elliott