dismiss modal view with return key - iphone

I got one UITextField on my Modal view controller.
When "Done" key is clicked, i want to dismiss the modal view.
i don't know where should i add below code to dismiss modal view.
Thanks in advance for any help.
[self.parentViewController dismissModalViewControllerAnimated:YES];

add it in UITextFieldDelegate method
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[self.parentViewController dismissModalViewControllerAnimated:YES];
return YES;
}

Related

findAndResignFirstResponder not dismissing keyboard

I have 6 UITextFields created in Interface Builder. After entering the values, and clicking the search button, I need to dismiss the keyboard from the view.
Currently I'm using 'findAndResignFirstResponder' and have delegates set for all text fields however the keyboard is not dismissing.
Any idea why this isn't working? Is there a better way to dismiss the keyboard?
use this
[self.view endEditing:YES];
this will resign keypad from all fields
in the IBaction "search"
[Field1 resignFirstResponder];
[Field2 resignFirstResponder];
[Field3 resignFirstResponder];
[Field4 resignFirstResponder];
[Field5 resignFirstResponder];
Try using [Field resignFirstResponder];
You could try to assign a UITextField to the FirstResponder and after that to resign the FirstResponder:
[someField becomeFirstResponder];
[someField resignFirstResponder];

Making return-key on keyboard dismiss it. IT WON'T

I dropped a UITextField into a view controller via Interface Builder called *txtNameField, added the UITextFieldDelegate to my view controller, and then set the field's delegate to self in the viewDidLoad of the view controller. I made a call to
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(#"textFieldShouldReturn");
[textField resignFirstResponder];
return YES;
}
but the return key does not dismiss the keyboard.
Any ideas?
Link a method to your textField's didEndOnExit event and put [textField resignFirstResponder]; in that method.

How to prevent dismissing of the popover control?

I don't want to dismiss popover controller when i touch any view. Is it possible?
I am using following code for displaying popover controller.
UIPopoverController* popoverCamera;
popoverCamera= [[UIPopoverController alloc] initWithContentViewController:videoRecorder];
[popoverCamera presentPopoverFromRect:CGRectMake(cropRectangleButton.frame.origin.x,cropRectangleButton.frame.origin.y,0,0) inView:innerview permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
NSLog(#"start recording-->%d",[videoRecorder startVideoCapture]);
[videoRecorder startVideoCapture];
[self presentModalViewController:videoRecorder animated:YES];
[videoRecorder release];
Yes it is possible. Implement the following delegate method:
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
Hope this might help you.
From the Link disable dismissal of uipopoverview controller
When displayed, taps outside of the popover window cause the popover to be dismissed automatically. To allow the user to interact with the specified views and not dismiss the popover, you can assign one or more views to the passthroughViews property. Taps inside the popover window do not automatically cause the popover to be dismissed. Your view and view controller code must handle actions and events inside the popover explicitly and call the dismissPopoverAnimated: method as needed.
implement the pop over delegate
/* Called on the delegate when the popover controller will dismiss the popover. Return NO to prevent the dismissal of the view.
*/
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController;
func popoverShouldClose(_ popover: NSPopover) -> Bool {
return false
}
Try this where you dont want to dismiss the popUp:-
[popOverController dismissPopoverAnimated:NO];
Hope this helps :)

Keyboard doesn't slide with view

When the view is dismissed the keyboard slides after the view.
I created a video to demonstrate the problem.
http://www.youtube.com/watch?v=ISFL5G17coU'
Does anyone know why this happens
In -(void) viewWillDisappear: make sure you call resignFirstResponder on your textfield.
- (void)viewWillDisappear:(BOOL)animated
{
[textField resignFirstResponder];
}

How to disable UIPopoverController animation?

I have added the popOvercontroller on click of navigation bar right button.i don't want the animation effect..can anybody tell me how to disable it???
There are two pieces to this. Using presentPopoverFromBarButtonItem:permittedArrowDirections:animated:NO or presentPopoverFromRect:permittedArrowDirections:animated:NO to present the popover will prevent the "appearing" animation. To disable the disable the "disappearing" I had to add this to the delegate:
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popover {
// Any cleanup code (popoverControllerDidDismissPopover won't be called)
[popover dismissPopoverAnimated:NO];
return NO;
}
How do you instantiate it? the docuemntation mentions presentPopoverFromBarButtonItem:permittedArrowDirections:animated: - sounds like the perfect answer to your question.
Btw. if you're showing a popover from a table view, you'll want to animate row deselection at the same time while popover is being dismissed. To achieve this, you can use:
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popover {
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
[popover dismissPopoverAnimated:YES];
return NO;
}