I think you have to made our own protocol for your custom TextField. In your custom textfield, you implement the UItextfieldDelegate protocols and you made your own to prevent the UIVIewController.
in your .h
@protocol YourCustomTextFieldDelegate <NSObject>
- (void) userDidChangeRange:(NSRange*) currentRange;
@end
@interface YourCustomTextField : UIView <UITextFieldDelegate> {
UITextField *_customTextField;
}
@property(nonatomic, weak) id<YourCustomTextFieldDelegate> delegate
in your .m
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
//Create your customTextField and add it to the view
_customTextField.delegate = self;
}
#pragma mark - UItextField Delegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange: (NSRange)range replacementString:(NSString *)string
{
[self.delegate userDidChangeRange:range];
return YES;
}
Edit :With notification post
in your .h
interface YourCustomTextField : UIView <UITextFieldDelegate> {
UITextField *_customTextField;
}
in your .m
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
//Create your customTextField and add it to the view
_customTextField.delegate = self;
}
#pragma mark - UItextField Delegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange: (NSRange)range replacementString:(NSString *)string
{
[[[NSNotificationCenter defaultCenter] postNotificationName:@"YourNotificationName" object:self userInfo:@{@"range": range, @"textFieldTag" : @"[NSNumber numberWithInt:self.tag]}];
return YES;
}
The user will listen to your notification with
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rangeDiDChange) name:@"YourNotificationName" object:nil];
}
I suggest that in the notification you set the tag to recognise your textfield, if you have many custom textfield in your view controller, to recognise it.
Hope it will help.