0

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];
Icoder
  • 330
  • 3
  • 25
  • Can you access the active input field? Then it might be a better idea to call resignFirstResponder on that view. – freytag Jul 08 '15 at 11:08
  • 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 Jul 08 '15 at 11:12
  • [textfield resignFirstResponser]; mannually – Rushi trivedi Jul 08 '15 at 11:53

1 Answers1

0

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:

ogres
  • 3,660
  • 1
  • 17
  • 16
  • I think you didn't get my issue.. Actually my issue is if I open and close the popover when keyboard is visible my keyboard gets locked after popover dismissial – Icoder Jul 08 '15 at 11:40
  • why are you opening a keyboard at all if you want to present popover and then decide which textfield will be first responder ? – ogres Jul 08 '15 at 11:40
  • I'm not presenting keyboard and popover at same time. In my case some of the textfields are customised which will open the popover and some of them will open the usual keyboard. If I tap on the textfield (not customised) keyboard will appear and then if I open and close the popover my keyboard gets locked... – Icoder Jul 08 '15 at 11:44
  • is it standard UIPopover ? are you doing this on iPad only ? do you have the same behavior on iPhone ? – ogres Jul 08 '15 at 11:46
  • Standard UIPopover my app is only for iPad – Icoder Jul 08 '15 at 11:46
  • I have the same behavior in one of my applications , but even when I open a popover , I can still use keyboard ( write something ) , are you overriding -becomeFirstResponder method ? can you hide keyboard ( with resignFirstResponder on the textfield which is now active ) before opening an UIPopover ? do you have any custom UIWindow changes in popover or textfield ? – ogres Jul 08 '15 at 11:49