I've got a modal view that has "Cancel" button (the button dismisses modal).
In the modal, I'm shoving a small UIPopover.
What I'm trying to achieve is:
When the UIPopover is visible, if uset touches "Cancel" it will do both:
hide popover (it's happening now, since that's the click outside popup)
hide modal - as if user touched "Cancel" without popup
Is there a way to do it?
UIPopoverControllerDelegate is not providing any help (or I'm not seeing it :) )
Thanks :)
Before presenting the popover, add the Cancel button to the popover's passthroughViews array:
popoverController.passthroughViews = [NSArray arrayWithObject:cancelButton];
This will let the Cancel button respond to touches while the popover is displayed without automatically dismissing the popover.
Then in your Cancel button's action method, call dismissPopoverAnimated: on the popover before dismissing the modal view.
You'll need to keep a reference to the popover in an ivar (eg. popoverController) to do this.
Related
I have some UITouch drag activity going on in the main view / controller that invokes a UIPopoverController. Surprisingly, the popover isn't dismissed when the user drags on the invoking view, though a single tap does dismiss it.
Does anyone know how to force a popover dismiss on a view drag? The view's touch events do not seem to be received, so my best guess is looking at the application's view events and try to figure out drags from there, but I'm not sure.
When displayed, taps outside of the popover window cause the popover to be dismissed automatically. To allow the user to interact with the specified views and not dismiss the popover, you can assign one or more views to the
passthroughViews
property. Taps inside the popover window do not automatically cause the popover to be dismissed. Your view and view controller code must handle actions and events inside the popover explicitly and call the
dismiss(animated:)
method as needed.
Docs: https://developer.apple.com/documentation/uikit/uipopovercontroller
Imagine a ViewController with 2 UITextFields. When you tap on TextField1, it appears a Popover.
Now, if I tap out of the popover, it disappears (OK). However, I want this behaviour:
If I click outside of the popover, and this tap is on TextField2, I want to dismiss the popover (OK), AND throw an event (for example, open other popover from TextField2).
I've tried this solution: Iphone SDK dismissing Modal ViewControllers on ipad by clicking outside of it
But handleTapBehind method doesn't execute if popover is visible.
Is it possible?
Thanks!
you should implement UIPopoverControllerDelegate
and use
popoverControllerShouldDismissPopover:
popoverControllerDidDismissPopover:
see More for details
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.
I have a UITableView within an UINavigationController. On the right of the UINavigationBar I have an "Edit" button. When I tap this button, all the textfields in the table cells become activated so I can edit them. The right button changes to "Save".
I'd now like the left "back" button of the UINavigationController to be replaced by a "Cancel" button which when I tap doesn't bring me back to the previous UIViewController, but just cancels editing mode.
When I tap "Save" the "Cancel" button should be changed back to the usual UINavigationController back button. Is there any easy way to do this? I tried accessing [[self navigationItem] leftBarButtonItem]. This works for the right button, but not the left one.
Set the leftBarButtonItem to your Cancel button. At the appropriate time, set the leftBarButtonItem to nil to remove your Cancel button. This will automatically restore the original back button that was in place before you added the Cancel button.
It sounds like the leftBarButtonItem is a "BackButton", which is set on the UIView(Controller) you used to navigate to the current View.
You can hide the BackButton following the answer in this question. This should be done, since you cannot change it's behavior.
I believe you are then able to use the leftBarButtonItem.
See this other SO question.
Then make sure you declare the cancel method similar to this.
(void)cancel:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
I use a floating popover to present suggestions in my UI. When the user wants to select an item from the menu bar in the splitview controller, the first tap just dismisses the popover. Therefore, the user has to tap twice, to activate a menu item.
If the user wants to activate the trash can, he has to tap it twice. Once to dismiss the other popover, and once to activate the trash can.
What's the best way to avoid this?
Wild guess here - but perhaps passThroughViews - add the button view and then in the button action, dismiss the popover (need to determine if it is active). A bit hacky but could work.