Reputation: 2451
My application is tab bar based application.i have to provide an option that user can change his profile picture in profile edit screen.for this I'm pushing profile edit screen from profile screen when user clicks on edit bar button.
UITabBarViewController --> UINavigationController -->ProfileView (UIViewController) --Push--> ProfileEditView(static UITableViewController)
I am presenting UIImagePickerController
using below code
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
// imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext; (when i use this TabBar hiding cancel and chose buttons)
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
and Delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
profileImage = info[UIImagePickerControllerEditedImage];
[_choseProfilePicButton setBackgroundImage:profileImage forState:UIControlStateNormal];
if ([picker isKindOfClass:[UIImagePickerController class]])
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
when i try to chose image and clicks on choose image current view going back to Profile screen(Profile screen --Push--> profile edit view-->presenting imagePicker controller --> selecting image --> going back to Profile screen).after selecting parent view is dismissing instead of image picker controller.Need to dismiss image picker controller and stay in same screen after selecting image.Please help me on this how to get rid of this....
Thanks,
Raki.
Upvotes: 3
Views: 1640
Reputation: 161
I was just in a wildly similar situation and solved the issue by setting the image picker's modalPresentationStyle
to "OverCurrentContext":
func photoButtonPressed(sender: AnyObject) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
picker.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
presentViewController(picker, animated: true, completion: nil)
}
Thanks to: ImagePicker dismiss tabBar Nav Controller
Upvotes: 8
Reputation: 944
1.Create a baseViewController.
2.Set the frame and add the baseController to your root viewcontrollers view.
3.Present your imagePickerController from baseViewController.
4.After successfully picking up image,remove the baseViewController's view from superview.
self.baseViewController = [[UIViewController alloc] init];
[APP_DELEGATE.rootViewController.view addSubview:self.baseViewController.view];
[self.baseViewController.view autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsFromString(@"0,0,0,0")];
//You can also set frame ,I have used purelayout so the above step
[self.baseViewController presentViewController: self.myPicker.imagePickerController animated:YES completion:^ {}];
//Last step after picking up image
[self.baseViewController.view removeFromSuperview];
Upvotes: 0