iOS Segues with Popover has undesirable default behavior - ios

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.

Related

Get Bounds after tap outside from a 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

Persistent Popover with VoiceOver

I have an iPad popover with a button that triggers a modal segue to a full-screen view controller. It works fine and the popover dismisses itself. But, when VoiceOver is on, the labels of the popover persist and this interferes with the user hearing the new screen's VoiceOver labels. Even though the popover is dismissed, I can see the outlines of its labels as they are selected in VoiceOver. What am I doing wrong?
Just to answer my own question, placing:
self.view.accessibilityViewIsModal = YES;
in my destination view controller's viewWillAppear: resolved the issue.

How do I resign a first responder in a modal view with a Navigation Controller?

I am finding it quite impossible to resign the first responder in my Modal View that is a Navigation Controller.
I have a search bar that I use to search through a tableview. I need to have it so that when I click on a cell, or navigate from the pushed view the keyboard disappears. I have tried calling
[_searchbar resignFirstResponder];
and doing a similar call for every view and subview in the modal view. Nothing causes the keyboard to hide.
Any ideas?
I've also tried using delegate methods, such as searchBarShouldEndEditing and also, calling the method on NavigationItemShouldPop.
I am at a complete loss.
Not sure if you have solved this already but this thread holds the key:
iPad keyboard will not dismiss if modal ViewController presentation style is UIModalPresentationFormSheet
For your particular case (same as mine) with the navigation controller within the modal form sheet look at the third answer.

Prevent popovers from displaying over presented views

I am attempting to display a passcode screen that appears after X amount of inactivity. I use presentViewController:animated:completion: on the root view controller, and it works as expected, except when a popover is already being displayed. The popover, displayed from a bar button item, appears over the presented passcode screen.
Is there a way to dismiss or hide all visible popovers when presenting a view controller?
Create and add a 2nd window over the first. Present the passcode screen in the 2nd window. This will allow it to appear over any and all views from the first window. When you dismiss the passcode screen, be sure to remove the new window and make the 1st one key again.
Do you have a reference to the popover? Then you can just call
[popover dismissPopoverAnimated:NO];
when you go to shop the passcode overlay.
EDIT
Looping through subviews and seeing if you can dimiss a popover. I'd really recommend trying to find some other way of doing things as this is just icky. But it should work (untested).
for (UIView* view in self.view.subviews) {
if([view respondsToSelector:#selector(dismissPopoverAnimated:)]){
[(UIPopoverController*)view dismissPopoverAnimated:NO];
}
}
NSNotifications are a good tool for this problem. Have all your views or controllers that present popovers listen for a notification named, say, WillPresentPasscodeScreen, and implement a method that dismisses the popover when the notification comes in. Then, before you present your passcode VC, post a WillPresentPasscodeScreen notification -- no more popovers, regardless of where you are in the app.

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.

Resources