UIActionsheet displaying in iPhone but not in iPad - ios

I have one actionSheet and after clicking on button of this another actionSheet is displayed. This is working fine in iPhone but in iPad second actionSheet does not appear after clicking on button of 1st actionSheet.

First of all, UIActionSheet existed before UIPopoverController and UIPopoverController isn't available on iPhone, so it's useful for backwards compatibility and universal apps.
Also, a UIActionSheet isn't necessarily presented in a popover, specifically, if you show it from a UIBarButtonItem or UIToolbar that is already inside a popover. It is then presented in a similar fashion as on the iPhone (sliding in from the bottom of the view controller). According to the HIG, you must not present multiple popovers at the same time (I once had an app rejected for that), so in cases where a view controller may be inside a popover (like in a standard split view app), you may want to use action sheets, if possible. Of course there are a lot of cases where you can't replace a popover with an action sheet, because an action sheet only shows a list of buttons and a title, whereas a popover can display any view controller.
I think that the animated parameter only has an effect when an action sheet is presented in the "classic" (as on iPhone) way.

.I think the issue is you are trying to present second action sheet before first one is dismissed.
In method
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
Check if the action sheet dismissed is first one and then present second one via
- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated
You can use tag property to differentiate between the two action sheets.

Related

Action on UIAlertController that does not dismiss AlertController? (Disable dismissing)

I have an action sheet (UIAlertController with style of UIAlertControllerStyleActionSheet) with a few actions, presented on an iPad as a popover. What I want is, when a user selects one of the options (say, the first one), I want the action sheet to transition to a different action sheet, using the "Show" (previously "Push") animation. Is this possible? Or, if this is not possible, is it possible to present the second action sheet as a popover from the action tapped (I'd prefer the transition method, if possible).
Thanks in advance!
The nice thing about iOS 7 and 8 in this regard is that it really is quite easy to write a view controller that looks and acts like an alert - except that it's just a view controller, so you can put any content you like into it and you can make it behave however you want.
For an example, see this github project of mine: https://github.com/mattneub/custom-alert-view-iOS7
As you'll see, all we're doing is starting with a small view designed in a .xib file and controlled by a view controller. Then we present the view controller. This view controller knows how to animate the appearance of the view and put a "dimmer" view behind it, just like an alert! And indeed this is not surprising, because in iOS 8 an alert controller is a presented view controller, so there's no reason why you shouldn't imitate its behavior. It isn't doing anything you can't do yourself.

UIActionSheet does not prevent external, "under" touches

I have a UIBarButtonItem in a navigation item that displays a UIActionSheet with a button to toggle a quick setting:
The action sheet is presented from the button item:
[calendarSettingsSheet showFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
However, here's the problem I'm encountering:
When I tap below the navigation bar, for example anywhere in the calendar, the UIActionSheet dismisses, which is expected. Any touch outside the sheet, in my opinion, should dismiss it.
But: I can still tap on the "Settings" and "Done" buttons in the navigation bar, and not only is the action sheet not dismissed, but the buttons function.
So, tapping "Settings" while the UIActionSheet is open, causes another to be opened. This can easily be avoided by checking to see if the action sheet is already open.
But, the "Done" button dismisses the entire calendar view, leaving the UIActionSheet hovering over the view that originally presented the calendar.
Is this intended behavior? While I could disable the buttons when the action sheet is presented, and enable them when it's dismissed, this seems like an unnecessary workaround.
Is this intended behavior?
Yes.
From the documentation of showFromBarButtonItem:animated:
On iPad, this method presents the action sheet in a popover and adds the toolbar that owns the button to the popover’s list of passthrough views. Thus, taps in the toolbar result in the action methods of the corresponding toolbar items being called. If you want the popover to be dismissed when a different toolbar item is tapped, you must implement that behavior in your action handler methods.

Dismissing UIActionSheet on iPad without animation

I have a horizontally scrolling UITableView on the bottom of my iPad app, and when the user taps on one of the cells, I pop up a UIActionSheet from it allowing them to select between two options.
That part works fine, but I'm running into two UI problems when dismissing the actionsheet.
1) When the user clicks outside of the UIActionSheet and not a different UITableViewCell, I'd like to deselect that cell immediately and then dismiss the UIActionSheet, or fade them both out at the same time. However, when I implement
(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
to do this, it still results in the actionsheet slowly fading out before deselecting the cell, which just looks a little odd. It happens whether I'm calling [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:NO], by getting that cell and changing the appearance manually, or reloading the table. Even if I maintain a reference to the UIActionSheet from when I create it (e.g. self.actionSheet) and set it to hidden or nil when willDismissWithButtonIndex is called, it still operates this way.
2) If the user clicks outside the UIActionSheet but selects another TableViewCell, I'd like to instantly shift the UIActionSheet to the other cell. Right now, however, it just fades out slowly and then the user has to tap the new cell again in order to bring up the UIActionSheet for that cell.
Anyone have suggestions or experience with this issue?
All the best,
Toby
From the UIActionSheet class reference:
For applications running on iPad devices, the action sheet is typically displayed in a popover that is anchored to the starting view in an appropriate way. Taps outside of the popover automatically dismiss the action sheet, as do taps within any custom buttons. You can also dismiss it programmatically.
So I do not think you can change the behaviour of this UIActionSheet when user taps outside to select another cell in your app. You might want to just create your custom pop over view to address your two issues.

ActionSheet within UISplitViewController acts different in Portrait Mode than Landscape Mode

I created a new application using the Split View-based Application template.
I then added an Action Button to the rootViewController navigation controller called actionButton.
When the button is pressed, I display an ActionSheet like this:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
otherButtonTitles:#"Admin Functions", #"Refresh Data", nil];
[actionSheet showFromBarButtonItem:actionButton animated:YES];
[actionSheet release];
After I press the button when in landscape mode it displays the action sheet in a popover which is pointing to the button (as I expected it to):
However, in Portrait mode it looks completely different and the menu comes up from the bottom of the rootViewController popover just like it does on the iPhone:
My question is, how do I make the ActionSheet appear at the top while in portrait mode, just like it does when in landscape mode?
Since this is a "utility menu", it isn't really tied directly to the data being displayed so it shouldn't be part of the popover.
This behaviour is by design, if it were a popover in portrait mode you would then have 2 levels of popover.
This is technically possible by implementing your own version of UIPopover or using one someone has already written (WEPopover).
However, this is a poor design choice. You say that the functions aren't related to the data, however one is 'refresh data'. I would replace the action button with a refresh icon such as the one Apple uses in 'Find my Friends':
The other, 'Admin Functions', if not directly related to the data in the list, perhaps needs a new home, maybe with the main view of your app? It's hard to say where is best to put it without knowing more about the structure.
Another possibility is that you could move the action button from right edge of the root view controller's bar to the left edge of the detail view controller's bar.
For example, if the action button were located just to the right of the vertical bar in your first screen shot (meaning it's at the left edge of the detail view controller's bar), then when you rotate to portrait mode it would appear just to the right of the Events button in your second screen shot. You could still call UIActionSheet's showFromBarButtonItem:animated method, which would display your action sheet in popup mode.
There's still the question of whether you really want two popovers on the screen at the same time. But if you do, this is how to do it.

How can I customize UIPopoverController view on iPad?

I am looking for a solution to customize PopoverController view in my iPad app. I need to remove the pointing icon along with the popover view and to make the view to the middle of the App window. It should go back to the button from where it is popped when we click on anywhere other than the popover view. USA TODAY app in iPad included such an option. I am not sure about how did they implemented it.
You would need to create your own custon view and animate your self. There is no Appple provided solution

Resources