Reputation: 1173
I have 4 tabs in my UITabBarController
and I present UIImagePickerController
from the 4th ViewController in my tabBar. (All the tabs viewControllers are embedded in UINavigationController
)
When my UIImagePickerController
is dismissing from my 4th tab, whether after selecting an image or just cancelling the picker, it takes me back to my first tab (0 index).
It should stay to my 4th tab viewController. Why is this happening? I have searched all in the code and there's no where I have mentioned tabBarController.setSelectedIndex = 0;
This is my code to present the UIImagePickerController
and dismiss it:
- (void)takeNewPhotoFromCamera
{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.allowsEditing = NO;
//controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
controller.delegate = self;
[self presentViewController: controller animated: YES completion: nil];
}
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
}
Please help.
Thanks!
Upvotes: 0
Views: 293
Reputation: 1173
Just found the solution by setting the image picker's modalPresentationStyle
to OverCurrentContext
:
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.allowsEditing = NO;
controller.delegate = self;
controller.modalPresentationStyle = UIModalPresentationOverCurrentContext; //This is the magical line
[self presentViewController: controller animated: YES completion: nil];
Upvotes: 3