Search code examples
iosiphoneuitextfielduikeyboard

UIKeyboardWillShowNotification coming when input view for textfield is different


I am using date picker as input view for textfield. In view will appear I have added UIKeyboardWillShowNotification.

My problem is that when the date picker is to be seen then also it comes KeyboardWillShowNotification method. How can I differentiate that keyboard is seen or date picker is seen, as I need to resize table view according to that

I have assigned inputview in textfieldDidBeginEditing

cell.txtField.inputView = datePicker; 

Solution

  • you can implement the (BOOL)textFieldShouldBeginEditing:(UITextField *)textField delegate and then save a local variable that you are editing your textfield at the moment like

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
       self.editingTextfield = YES;
    }
    

    and in your (BOOL)textFieldShouldEndEditing:(UITextField *)textField you set that flag to false

    -(BOOL)textFieldShouldEndEditing:(UITextField *)textField {
       self.editingTextfield = NO;
    }
    

    in your KeyboardWillShowNotification notification you can check that flag to see which control issued the keyboard