Reputation: 820
I have a tab bar application with several controllers. Some are UINavigationControllers
, some just simple UIViewControllers
.
The central button presents the UIImagePickerController
to allow the user to take a picture.
When I present the Image Picker from a simple UIViewControllers
, it works fine.
But when I present it while a UINavigationController
is currently the selectedViewController
, the dismall of the picker removes the UINavigationBar
of the controller.
I read that with UINavigationControllers
, the modal view must be presented from the navigationController
, but it does not work either.
Here are bunches of code :
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if (TARGET_IPHONE_SIMULATOR)
{
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
else
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else
{
UIAlertView* alert = [[UIAlertView alloc]
initWithTitle:@"Erreur"
message:@"Pour pouvoir poster des photos, votre device doit posséder un appareil photo"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
return;
}
}
if ([self.selectedViewController respondsToSelector:@selector(presentViewController:animated:completion:)])
{
[self.selectedViewController presentViewController:picker animated:YES completion:nil];
}
else
{
[self.selectedViewController presentModalViewController:picker animated:YES];
}
the dismall :
[self.selectedViewController dismissModalViewControllerAnimated:YES];
Has anyone got this strange behavior (guess it has something to do with the fact that UIImagePickerController
delegate must implement UINavigationControllerDelegate
) and know how to resolve that?
Thanks.
Upvotes: 0
Views: 3066
Reputation: 820
It was actually really more simple : in the viewWillAppear
, I set the hidden property to NO
and in the viewWillDisappear
I set it to YES
. The thing is : when the modal controller is presented, the viewWillDisappear
was called. But when it was dismissed, the viewWillAppear
was not called... Not really the expected behavior, but still. Thanks guys.
Upvotes: 1
Reputation: 31091
You can redirect to pickerController using this
[self presentViewController:picker animated:YES completion:^{}];
And its delegate method
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
[picker dismissViewControllerAnimated:YES completion:^{}];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
Or
Make sure that you are not setting any setHidden
in your Code.
Upvotes: 1