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];
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:
Related
When I tap the go button on the keyboard I push to a new view controller, but for a split second on the new view controller the old keyboard is still showing, how can I resign the keyboard so it doesn't appear on the new view controller I have tried both
[self.view endEditing:YES];
And this
[_passwordField resignFirstResponder];
in the prepareForSegue method and the same two lines in the IBAction
I think you have first tying to push to a new view controller, after that you are code for hide keyboard. Use following code for your problem, use this delegate method textFieldShouldReturn.
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
if ( textField == _passwordField){
[_passwordField resignFirstResponder];
//After that Push to a new view controller From Here
}
return TRUE;
}
I want to resign first responder from the currently edited textfield when a row is selected in the UITableView and a push segue is triggered inside a navigation controller. This is happening within a popover.
I've tried two things:
(1) I can see that the textfield is resigning the first responder while animating, but then when I go back to the view controller it takes first responder again and shows the keyboard.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.view endEditing:YES];
}
(2) This will prevent the restoring of the editing when going back to the view controller, but this method breaks the animation. In the end of the animation, the first view controller gets black and it jumps a little bit.
EDIT: Just realized that this is only visible in landscape mode as it has something to do with that the keyboard animates faster than the push animation, and it gets black as soon as the keyboard is gone and the popover starts to animate to a higher height when the keyboard leaves room for it. The animation can't handle expanding the popover while animating the push animation in the navigation controller. When removing the code below and pushing and letting iOS remove the keyboard, the keyboard and push animation is taken exactly the same time and avoiding this issue. I wonder how I can make that happen myself while forcing the resignation.
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.view endEditing:YES];
return indexPath;
}
How can I resign first responder when changing view controller without it restoring the first responder on the text field again when navigating back?
Hold on a minute. So the issue is that when you perform the segue (and dismiss the view) when the view restores it has a sort of shadow of the keyboard showing. Is that it? In that case. You could try the following. when you click the tableviewcell. Do a check. like the following.
if(firstResponder != nil){
//register for keyboard hide notification
[[NSSnotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:#"UIKeyboardDidHideNotification" object:nil];.
[firstResponder resignFirstResponder];
} else {
[self performSegue:#"yoursegueidentifier" withSender:nil];
}
That will only launch the segue if there is not a responder (and hence, not a keyboard). If there is a keyboard, it registers for the keyboard hide notification, and then resigns the responder. Then, in the method that responde to the keyboard hiding
- (void)keyboardDidHide:(NSNotification *)notification {
[self performSegue:#"yoursegueidentifier" withSender:nil];
}
This should only perform the segue when the keyboard has hidden, so it should resolve the animation issue. You may need to modify your storyboard to have the segue launch from the view controller and not from the cell's button, I'm not sure about how your architecture is. let me know if this works or not.
I am using FPPopover. Everything works well until I want to present the popover when there is a keyboard. The sequence of events are:
click on a text field
keyboard shows up as usual
click a button to trigger popover
Here is the FPPopover code to add its view:
NSArray *windows = [UIApplication sharedApplication].windows;
if(windows.count > 0)
{
_parentView=nil;
_window = [windows objectAtIndex:0];
//keep the first subview
if(_window.subviews.count > 0)
{
_parentView = [_window.subviews objectAtIndex:0];
[_parentView addSubview:self.view];
[_viewController viewDidAppear:YES];
}
}
How can I make the popover view not overlapped by the keyboard?
Did you want to have the keyboard visible at all times? If not, have your view dismiss the keyboard when the modal view is presented.
You can do this by calling sending resignFirstResponder to a view object (such as a textView).
Once the modal view is closed, send becomeFirstResponder.
I got a simple detail view with a textfield.
In detail's viewController I wrote this code:
- (void) viewDidAppear:(BOOL)animated{
[self.textField becomeFirstResponder];
NSLog(#"is textField 1st responder %d", [self.textField isFirstResponder]);
}
When I push the detail into a navigation controller, I see "is textField 1st responder 0" in my log.
The keyboard doesn't appear.
But the textfield has blinking cursor.
What happens in this moment? Why the keyboard doesn't appears? I did try to catch a notification "KeyboardDidShown" in my AppDelegate but didn't catch anything:
Here is my master view design :
Does calling reloadInputViews help?
I have UIView with few UITextFields. On load I call [textfield becomeFirstResponder] to bring keyboard on the screen. I don't want to dismiss this keyboard until I done with view.
Keyboard dissapear after I "touch" outside any textfield.
I tried to set
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
return NO;
}
however then I can't dismiss keyboard even after is unloaded.
Any hints how to keep keyboard all the time and dissmiss it just before uiview remove?
When viewWillDisappear (or viewDidDisappear) is called, then call resignFirstResponder on your UITextField.
- (void) viewWillDisappear:(BOOL) animated {
[self.textField resignFirstResponder];
}
call this line before dismiss.
view.endEditing(true)