Presenting a UIPopover from a UIActionSheet
Asked Answered
H

2

5

My problem is quite simple but I can't find a way around it. When a button is pressed I present a UIActionSheet with two options (library/camera). When the users presses a button on the UIActionSheet I present a UIPopoverController with the photo library or present the camera modally.

When a button on the action sheet is pressed I get the following warning in the console:

Warning: Attempt to present <UIImagePickerController: 0x17ae1600> on <MyViewController: 0x17a3ca00> which is already presenting <UIAlertController: 0x1884acb0>

Any ideas on a suitable workaround?

Hooligan answered 3/10, 2014 at 9:6 Comment(0)
J
16

I found this was happening on iOS8. I was presenting the popover from within actionSheet:clickedButtonAtIndex:. The solution for me was to use actionSheet:didDismissWithButtonIndex: instead.

Jobless answered 3/10, 2014 at 11:4 Comment(2)
The issue also started occurring on iOS 8 for me. I just tested this solution and it works, thanks. Although the previously selected answer also works this is a better solution.Hooligan
This only worked for me after I turned off the animation for displayiing the action sheet in the first place.Inwrap
H
0

I'd suggest waiting until the UIActionSheet is hidden before presenting another view controller. So move the code that presents the new view controller from the actionSheet:clickedButtonAtIndex: method into another method and call it asynchronously, i.e something like [self performSelector:@selector(presentImagePicker) withObject:nil afterDelay:1.0];

The 1 second delay allows the actionsheet to be hidden before another view controller is presented.

Hux answered 3/10, 2014 at 9:43 Comment(4)
Thanks. This works well, although I don't like forcing a delay. If there aren't any better soltuions I will use this.Hooligan
1 second might be conservative- you may get away with a shorter time (perhaps in fact anything above zero). As long as the action sheet is animating out though, I think you'll find that there will be something happening on-screen in response to their tap and the user won't much notice the delay.Hux
I changed the delay to 0.25 and it still works and is a little smoother. Thanks for your help.Hooligan
This solution worked but I have selected the other solution as the answer as it seems like a more correct way of doing things.Hooligan

© 2022 - 2024 — McMap. All rights reserved.