Warning message after clicking "Actions"

I am very new to iOS development and have encountered a bug that I just cannot find a solution to. I searched everywhere for solutions, but perhaps it was my novelty that kept me from seeing the problem.

The exact warning that is printed in the log:

Trying to reject a view controller <_UIAlertShimPresentingViewController: 0x7aaa4b90> while a presentation or firing is in progress!

This happens right after I click on the button on the action bar.

Here is the code:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { if (buttonIndex == 0) { picker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:picker animated:YES completion:nil]; } else if (buttonIndex == 1) { picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:picker animated:YES completion:nil]; } else if (buttonIndex == 2) { picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [self presentViewController:picker animated:YES completion:nil]; } } else { if (buttonIndex == 0) { picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:picker animated:NO completion:NULL]; } else if (buttonIndex == 1) { picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [self presentViewController:picker animated:YES completion:NULL]; } } } 

Implementing actionSheet, I have an IBAction associated with the toolbar button located in the .xib file.

  - (IBAction)addImage:(id)sender { UIActionSheet *popUpSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil]; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { [popUpSheet addButtonWithTitle:@"Camera"]; [popUpSheet addButtonWithTitle:@"Photo Library"]; [popUpSheet addButtonWithTitle:@"Camera Roll"]; [popUpSheet addButtonWithTitle:@"Cancel"]; popUpSheet.cancelButtonIndex = popUpSheet.numberOfButtons-1; } else { [popUpSheet addButtonWithTitle:@"Photo Library"]; [popUpSheet addButtonWithTitle:@"Camera Roll"]; [popUpSheet addButtonWithTitle:@"Cancel"]; popUpSheet.cancelButtonIndex = popUpSheet.numberOfButtons-1; } [popUpSheet showFromBarButtonItem: self.toolbarItems[0] animated:YES]; } 

Everything was delegated correctly from what I can say:

DetailViewController.m

 @interface DetailViewController () < UINavigationControllerDelegate, UIImagePickerControllerDelegate > 

DetailViewController.h

 @interface DetailViewController : UIViewController <UIActionSheetDelegate> 

Any insight would be appreciated and very helpful.

0
source share
2 answers

Your code looks correct. Try using:

 actionSheet:didDismissWithButtonIndex: 

method. It is sent to the delegate after the animation ends. Hope this helps.

+1
source

Finally figured out the problem. The compiler gave me this warning because recently Apple combined UIActionsheet and UIAlert into one type of controller called UIAlertController. Used the new UIAlertController controller and my problem was resolved.

 - (IBAction)addImage:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; UIAlertController *popUpSheet = [UIAlertController alertControllerWithTitle:nil message:@"Select your Choice" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *photoLibrary = [UIAlertAction actionWithTitle:@"Photo Library" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:picker animated:YES completion:nil]; NSLog(@"Photo Library was touched"); [popUpSheet dismissViewControllerAnimated:YES completion: nil]; }]; UIAlertAction *recentPhotos = [UIAlertAction actionWithTitle:@"Camera Roll" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [self presentViewController:picker animated:YES completion:nil]; NSLog(@"Camera Roll was touched"); [popUpSheet dismissViewControllerAnimated:YES completion: nil]; }]; UIAlertAction *camera = [UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { picker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:picker animated:YES completion:nil]; NSLog(@"Camera was touched"); [popUpSheet dismissViewControllerAnimated:YES completion:nil]; }]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [popUpSheet dismissViewControllerAnimated:YES completion:nil]; }]; [popUpSheet addAction:photoLibrary]; [popUpSheet addAction:recentPhotos]; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { [popUpSheet addAction:camera]; } [popUpSheet addAction:cancel]; [self presentViewController:popUpSheet animated:YES completion:nil]; } 
0
source

Source: https://habr.com/ru/post/1263664/


All Articles