Error on Presenting FDTake - ios

I got a error on Presenting FDTake (Github-Link) FROM a PRESENTED TableViewController:
Warning: Attempt to present UIImagePickerController: 0x14454a880 on NavigationViewController: 0x14452f900 whose view is not in the window hierarchy!
NavigationViewController is a subclass of UINavigationController. It's from REMenu (https://github.com/romaonthego/REMenu).
Any Idea how I can solve it? I already wrote a Issue to the repository but nobody answered, so I thought maybe you guys know why.

I have never used that library though I can share my code for the same functionality with you. Feel free to use it whereever you were using FDTake. Don't forget to set Actionsheet and UIImagePickerController Delegates.
-(IBAction)chooseProfilePicture:(id)sender
{
UIActionSheet *filterActionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Operation"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Choose from gallery", #"Take Photo", nil];
[filterActionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
switch (buttonIndex) {
case 0:
[self.navigationController presentModalViewController:imgPicker animated:YES];
break;
case 1:
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
imgPicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imgPicker.mediaTypes = #[(NSString *) kUTTypeImage];
imgPicker.allowsEditing = NO;
[self presentViewController:imgPicker
animated:YES completion:nil];
//_newMedia = YES;
}
break;
default:
break;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
{
[picker dismissModalViewControllerAnimated:YES];
//Do what you want with the captured/selected image
}
It's that simple. Not really a need for using third party libs for that. Not an answer to your question but it is relevant in some fashion.

Related

Attempt to present UIImagePickerController on UITabBarController while a presentation is in progress

I need help for resolving a warning error. I use a UIImagePickerController and it's showing when I tap on the third tab on my tabBar. When I cancel, I want to show the last tab before the selection of the camera, but when I dismiss my picker, I get a warning!!
This is my code and I don't understand why I get the warning...
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self showPickerController];
}
- (void) showPickerController
{
imagePicker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
} else{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Erreur !"
message:#"Votre iPhone n'a pas de Camera"
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[message show];
}
[self presentViewController:imagePicker animated:NO completion:nil];
}
#pragma mark - Camera Methods
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self.tabBarController dismissViewControllerAnimated:NO completion:^{
if(self.tabBarController!=nil)
[self.tabBarController setSelectedIndex:0];
}];
}
Any idea?
In addition to danh's answer, add a BOOL property to your view controller and add a bit of code to your viewDidAppear: method:
#property (nonatomic) BOOL appeared;
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (!self.appeared || [self isMovingToParentViewController] || [self isBeingPresented]) {
self.appeared = YES;
[self showPickerController];
}
}
This will keep the UIImagePickerController from being immediately presented again after being dismissed.
Also, this isn't really relevant to the question, but you might want to change your showPickerController method a bit to prevent from showing an empty UIImagePickerController if there's no camera available:
- (void)showPickerController
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:NO completion:nil];
}
else {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Erreur !"
message:#"Votre iPhone n'a pas de Camera"
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[message show];
}
}
Simple idea: change this to:
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self showPickerController];
}
Probably a better idea is to detect the source-type-available condition before beginning the transition to this vc, and instead present the picker vc instead.

iOS app with camera popup

I am developing an iOS 7 app in xcode 5. I am using the camera functionality. When the user presses the camera button in my app, I want to give him a choice: take a new picture or choose a picture from the "photostream". I want to show a popup with the choice like "WhatsApp" does, or like the Apple Message app.
I thought; I create an Table View Controller with a section and three cells: take a picture, choose from "photostream" and cancel. I set this section at the bottom of the Table View and make the background transparent. But is does not work ;)
I also searched on Google, but I did not found anything that could help me.
Can anyone tell me how I could do it?
Try this. You have to use UIActionSheetDelegate and UIImagePickerControllerDelegate
- (IBAction)changePhotoButtonPressed:(id)sender {
UIActionSheet *actionSheet=[[UIActionSheet alloc] initWithTitle:#"MY APP"
delegate:self
cancelButtonTitle: nil
destructiveButtonTitle: nil
otherButtonTitles:#"Take From Camera",#"Select From Library", #"Cancel", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
actionSheet.destructiveButtonIndex=2;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
}
UIActionSheet Delegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex==0) {
[self takePictureFromCamera];
}
else if (buttonIndex==1) {
[self pickImageFromLibrary];
}
}
Other Methods:
-(void) pickImageFromLibrary
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController* imgPicker=[[UIImagePickerController alloc] init];
self.imagePicker = imgPicker;
//UI Customization
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[[self.imagePicker navigationBar] setTintColor:[UIColor whiteColor]];
}
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePicker.delegate = self;
[self presentViewController:self.imagePicker animated:YES completion:nil];
} else {
NSLog(#"Attempted to pick an image with illegal source type '%d'", UIImagePickerControllerSourceTypePhotoLibrary);
}
}
-(void) takePictureFromCamera
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController* imgPicker=[[UIImagePickerController alloc] init];
self.imagePicker = imgPicker;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.delegate = self;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[[self.imagePicker navigationBar] setTintColor:[UIColor whiteColor]];
}
[self presentViewController:self.imagePicker animated:YES completion:nil];
} else {
NSLog(#"Attempted to pick an image with illegal source type '%d'", UIImagePickerControllerSourceTypePhotoLibrary);
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"MY APP" message:#"CAMERA_NOT_AVAILABLE" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
}
You should use an UIImagePickerController and set its type to either UIImagePickerControllerSourceTypeCamera or UIImagePickerControllerSourceTypePhotoLibrary.
And for the popup with the choices, use an UIActionSheet.
You can have a look at this sample code form Apple for the UIImagePickerController:
https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html

Hide ActionSheet iOS

My application is about clicking on a button with background image named "uploadphoto1.png". When I click on the button, it shows me an ActionSheet letting me choose to take a picture with the camera or taking a picture from the library.
When, for example, I choose a picture from the camera, it lets me select a picture and show the picture in an imageView and it change the background image of the button from upload.png to save.png.
The problem now that when I click on the button with background Image "save1.png" it shows me the actionSheet.
I want to hide the actionSheet.
Here is the code:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *buttonpicture =[UIImage imageNamed:#"uploadphoto1.png"];
[ButtonPicture setBackgroundImage:buttonpicture forState:UIControlStateNormal];
[ButtonPicture setFrame:CGRectMake(173, 269, 140, 30)];
}
- (IBAction)ButtonPicture:(UIButton *)sender
{
NSLog(#"Button Picture Pressed");
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:#"Photo" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Picture From Camera",#"Picture From Gallery",nil];
[actionSheet setTag:1001];
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex)
{
case 0:
{
// Take a picture from camera
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
break;
case 1:
{
// take a picture from gallery photos
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self.view addSubview:toolbar];
[self presentModalViewController:picker animated:YES];
}
break;
default:
break; }
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[ButtonPicture setBackgroundImage:[UIImage imageNamed:#"save1.png"] forState:UIControlStateNormal];
[picker dismissModalViewControllerAnimated:YES];
imageview.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
//[actionSheet showInView:Nil];
}
#interface YourViewController
{
BOOL imageChanged;
}
- (void)viewDidLoad
{
[super viewDidLoad];
imageChanged = NO;
UIImage *buttonpicture =[UIImage imageNamed:#"uploadphoto1.png"];
[ButtonPicture setBackgroundImage:buttonpicture forState:UIControlStateNormal];
[ButtonPicture setFrame:CGRectMake(173, 269, 140, 30)];
}
- (IBAction)ButtonPicture:(UIButton *)sender
{
NSLog(#"Button Picture Pressed");
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:#"Photo" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Picture From Camera",#"Picture From Gallery",nil];
[actionSheet setTag:1001];
if (!imageChanged)
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex)
{
case 0:
// Take a picture from camera
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
break;
case 1:
// take a picture from gallery photos
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self.view addSubview:toolbar];
[self presentModalViewController:picker animated:YES];
break;
default:
break;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[ButtonPicture setBackgroundImage:[UIImage imageNamed:#"save1.png"] forState:UIControlStateNormal];
imageChanged = YES;
[picker dismissModalViewControllerAnimated:YES];
imageview.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
There are various ways this could be handled. One way is to set a boolean flag when you don't want tapping on the button to bring up the actionSheet. Then, in - (IBAction)ButtonPicture:(UIButton *)sender you can check the boolean flag to decide whether or not to create the actionSheet and show it.

Passing an image from one view to other iOS

I have 2 UIViewControllers in my app.
In the 1st viewController, i have a UIButton in a toolbar.
When i click on the button, it displays me a UIActionSheet to select whether to take a picture from camera or from gallery.
When i choose, for example, taking picture from gallery and i choose a picture, it displays the picture in the 1st viewController.
What i want is to take a picture from gallery photos or from camera and to go to the 2nd viewController and display the image in the 2nd viewController.
I searched a lot and tried so much codes but it doesn't work.
Here is the code of ViewController.m
- (IBAction)PictureButton:(UIButton *)sender {
NSLog(#"Click button take picture in toolbar view 1");
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Photo"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Picture From Camera", #"Picture From Gallery", nil];
[actionSheet setTag:1001];
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex)
{
case 0: {
// Take a picture from camera
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
break;
case 1: {
// take a picture from gallery photos
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self.view addSubview:toolbar];
[self presentModalViewController:picker animated:YES];
}
break;
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
In my second view i created a UIImageView here is my code in SecondViewController.h
#interface SecondViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIImageView *imageButton;
#end
Can You help me please.
Sorry for my bad English and thanks
It seems you want to select image at FirstViewController and display it in SecondViewContoller. However, you did not do anything to switch to SecondViewController and pass your selected image to it in ViewController.m.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
secondViewController.imageButton.image = image;
[self.navigationController pushViewController:secondViewController animated:YES];
}

Displaying ImagePickerController From ActionSheet on iPad

Background: On iPad, I have a button which when tapped, showed a UIActionSheet. This action sheet has 2 options, camera and gallery. Camera when tapped, pulled up a camera and everything works fine. Gallery when tapped, suppose to show a popover with user's photos in it.
Problem: On iPad, UIActionSheet acts like a popover. Which when presenting, another popover cannot come into view. Error:Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.
My code:
Setting Action Sheet
- (void)imageButtonTapped:(UIButton *)sender
{
if (_commentObject.image){
_actionSheet = [[UIActionSheet alloc] initWithTitle:#"Action" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Remove" otherButtonTitles:nil];
_actionSheet.tag = ACTION_IMAGE_REVIEW_TAG;
}else{
_actionSheet = [[UIActionSheet alloc] initWithTitle:#"Image Source" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Camera", #"Gallery", nil];
_actionSheet.tag = ACTION_IMAGE_SOURCE_TAG;
}
if (_isPad) {
[_actionSheet showFromRect:_imageButton.frame inView:_scrollViewContent animated:YES];
}else{
[_actionSheet showInView:self.view];
}
}
Delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (actionSheet.tag) {
case ACTION_IMAGE_SOURCE_TAG:
switch (buttonIndex) {
case 0:
[self pickImage:YES];
break;
case 1:
[self pickImage:NO];
break;
default:
break;
}
break;
}
Executing
- (void)pickImage:(BOOL)fromCamera
{
if (fromCamera) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController* cameraPickerController = [[UIImagePickerController alloc] init];
cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPickerController.delegate = self;
[self presentViewController:cameraPickerController animated:YES completion:nil];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Camera Unavailable" message:#"Your Device does not support Cameras" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
}else{
UIImagePickerController *galleryPickerController = [[UIImagePickerController alloc] init];
galleryPickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
galleryPickerController.delegate = self;
if (_isPad) {
if ([_actionSheet isVisible]) {
[_actionSheet removeFromSuperview];
UIPopoverController *imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:galleryPickerController];
[imagePickerPopover presentPopoverFromRect:_imageButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}else{
[self presentViewController:galleryPickerController animated:YES completion:nil];
}
}
}
Question: I tried removing the action sheet from view, and tried dismissing it before executing pickImage. None of that works. How do I present the gallery?
Your Problem: Error:Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.
make Object of UIPopoverController in your .h file class. Make sure that your #property for your UIPopoverController is strong instead of weak.
Check this
UIPopoverController: dealloc reached while popover is still visible
UIPopovercontroller dealloc reached while popover is still visible
FYI, This was a comment and OP asked to put it as an answer. Because this solved the issue.
It's happening because you don't have a reference to your UIPopoverController. Have a strong reference for your imagePickerPopover and then try. No problem will occur.
you can try this:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if ([actionSheet isVisible]) {
[actionSheet dismissWithClickedButtonIndex:0 animated:NO];
}
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIImagePickerController *galleryPickerController = ......
}
}

Resources