I have an iPad app that uses a UIPopover from within a UIVIew; I need to show an alert-type message when a certain condition has been met.

The problem is using a UIAlertView from within the UIPopover, when the user taps on a button in the UIAlertView, it also dismisses the UIPopover, which defeats the purpose of the alert.

I tried using UIActionSheets, but they don't display at all, probably because they are not being called from a controller-type view.

Is there a way to circumvent this behavior?

有帮助吗?

解决方案

No, and you shouldn't do that. Popovers are supposed to go away as soon as you touch anything else.

You could enlarge the popover slightly and make room for a status message. When the user creates an appointment that overlaps, you could display a message in the status area.

Or, you could dismiss the popover and display an alert with "ok"/"cancel" buttons. The OK button would create the overlapping appointment, and the cancel button would discard it.

You will need some place to save the info from the popover while you are waiting for the user to decide what to do with the alert. Perhaps have the popover pass a message back to the view controller it comes from, and then have the source view controller create the alert, set itself as delegate, and handle the responses from the user.

其他提示

According to Apple's Human Interface Guidelines, it is OK to display a UIAlertView on top of a popover:

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/MobileHIG/Alerts.html

To quote specifically:

On iPad, don’t display a modal view on top of a popover. With the possible exception of an alert, nothing should display on top of a popover.

Displaying a UIAlertView from a popover does not automatically dismiss the popover. There is likely some of your own code being executed which is causing it to dismiss. For example, in a similar situation I had, I found that displaying a UIAlertView was invoking "shouldAutorotate" in my split view controller, and (due to earlier iOS bugs) I had placed code there to dismiss the popover. For iOS7+ this was no longer necessary, so I was able to move this code into willRotateToInterfaceOrientation, where it no longer causes dismissal of the popover upon display of UIAlertView, because in this case, even though "autoRotate" gets called "willRotateToInterfaceOrientation" does not.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top