0
votes

There are multiple textfields in a viewcontroller in which some of them are customised (one tapping those textfield will launch a popover controller, from that user can select the option which will get displayed in tapped textfield).

I have a tap gesture on the view controller for dismissing the keyboard (if it's on the screen).

Keypad gets locked(if it's visible) when I open the popover controller on taping the customised textfield. The keyboard is not getting dismissed even if I tap on the parent view or else on the dismiss button in the keypad.

I have tried this 2 snippets to hide the keyboard, but it's not working

[self.scrollView endEditing:YES];
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
1
Can you access the active input field? Then it might be a better idea to call resignFirstResponder on that view.freytag
Yes I can, but there is no use in getting the active field, because it's a customised (means it won't popup the keyboard , it will just shows the popup).Icoder
[textfield resignFirstResponser]; mannuallyRushi trivedi

1 Answers

0
votes

You can use textfields delegate to prevent it from presenting a keyboard and instead present popover yourself by implementing this textFieldShouldBeginEditing method

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if(textField == myCustomTextField) {
        [self openCustomPopover];
        return NO;
    }
    return YES;
}

more on its delegate methods here https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITextFieldDelegate/textFieldShouldBeginEditing: