Dismissing UIActionSheet on iPad without animation - ipad

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.

Related

UIActionsheet displaying in iPhone but not in iPad

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.

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.

Different popover for editing and non editing text field

Ok, sorry if the title is a little off. Hope I explain it better here. What I want to do is have a popover (iPad app) that will do different things based on the state of a UITextField. So if the user is typing in that text field and then taps the popover button, the popover appears and if the user taps something in that popover it will get added to that text field (think something like adding often used text). In this situation the popover will only disappear when the text field finishes editing.
However if the user taps the popover button when the text field is not editing then that list of items still appears but now it should disappear if the user taps outside the popover.
I hear something about pass-through views, but I'm not certain that is what I need.
Does anybody know a good way to do this?
The passthrought views are views outside the popover that don't cause it to dismiss automatically. When you want to dismiss the popover from your code when the textfield has finished editing call [myPopover dismissPopoverAnimated:YES].
For adding text blocks into the textfield I think delegation is the right thing to do. You set the your main view as the delegate of the conten view of the popover and each time a text block in the popover is selected you tell the delegate to add this block to the textfields text.
When you want to prevent the popover from dismissing while the textfield is being edited you should implement the UIPopoverControllerDelegate methode popoverControllerShouldDismissPopover:.

stop popoverViewController resignFirstResponder after dismissed

I am using a uitableview containing multiple rows, and each row contains two UITextFields side by side. let's say TextField1, TextField2. When a user taped on TextField1, and start typing, a popoverViewController shows up for suggestions. When the user tap on a suggestion from the popoverViewController, the popover dismissed (this is what i want), then the keyboard dismissed as well (this is not what i want). if now the user tap on TextField2, the keyboard comes up.
I want to keep the keyboard up because the user needs to input in TextField2.
How can i make this happen?
really appreciated.

iOS Segues with Popover has undesirable default behavior

I've got a weird issue with segues - I have a segue open a popover when a UIButton is tapped, all of this done through IB. (This is on iPad)
But when I select an option from the Tableview on this popover I want it to dismiss the popover. And I don't want the popover to open twice if the user taps that UIButton twice..
The way things work by default, tapping that UIButton keeps opening popovers on top of each other "forever" and also I still have the issue that when a cell from my Tableview is tapped, the popover remains.
How can I solve these problems?
Use prepareForSegue: method to dismiss the pop over if it is already present.
Here is given, how to use that method.
Prevent multiple popovers:
Use an if statement to determine whether a popover is present or not, if it isn't present it, if it is don't.
Dismiss on cell tap:
In didSelectRowAtIndexPath call dismissPopover on your popover view.

Resources