Reputation: 4565
i'm new in Objective C . What i'm going to do is simple just to animate keyboard up when textfield is focused and shrink when it's not. I already followed some other tutorial on how to set up this step by step but it not working.The event textViewDidBeginEditing is never get called when textfeld is focus.
@interface ViewController : UIViewController<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *cCodeTextField;
@property (weak, nonatomic) IBOutlet UITextField *jidTextField;
- (IBAction)nextBtnTapped:(id)sender;
@end
I'm also set the delegate to the textfield but it's not working.
- (void)viewDidLoad {
[super viewDidLoad];
[self addTextFieldBorder:_jidTextField];
[self addTextFieldBorder:_cCodeTextField];
_jidTextField.delegate = self;
}
-(void) textViewDidBeginEditing:(UITextView *)textView {
NSLog(@"Enter");
}
Upvotes: 0
Views: 579
Reputation: 54
It looks like your ViewController class is implementing methods from the wrong delegate. It is implementing UITextViewDelegate methods when it should be implementing UITextFieldDelegate methods.
Note that 'jidTextField' is of type UITextField.
Your delegate method is called 'textViewDidBeginEditing' which is a UITextViewDelegate method and takes a UITextView as a parameter.
The issue here is that your class is implementing delegate functions for UITextViewDelegate and not UITextFieldDelegate.
The correct method definition is:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
Here is a link to the documentation for the correct delegate: https://developer.apple.com/reference/uikit/uitextfielddelegate
Hope this helps!
Upvotes: 1