I am facing a problem regarding cursor move. I have applied below solution and it is not working:
In ViewController.h file
@interface ViewController : UIViewController<WJTextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textField;
@end
In ViewController.m file,
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) textFieldDidChangeSelection:(UITextField *)textField
{
NSLog(@"Function is hit");
}
@end
Subclass UITextField as follows.
@interface WJTextField : UITextField
@end
@protocol WJTextFieldDelegate <UITextFieldDelegate>
- (void) textFieldDidChangeSelection: (UITextField *) textField;
@end
Implementation:
@implementation WJTextField
- (void) setSelectedTextRange: (UITextRange *) selectedTextRange
{
[super setSelectedTextRange: selectedTextRange];
if ([self.delegate respondsToSelector: @selector(textFieldDidChangeSelection:)])
[(id <WJTextFieldDelegate>) self.delegate textFieldDidChangeSelection: self];
}
@end
But it is not hitting textFieldDidChangeSelection callback. Will anyone please help?
Note that, I have checked answer from below link: [UITextField -- observe changes to selectedTextRange?