Question

I am in Xcode 4.5, with an iOS6 target. Preamble: I have a libraryView (presenting view controller), with a popover containing a search. After the presentation of the search results, tapping a row dismisses the library and segues to entryView. That all works just fine. My issue: upon closing entryView and returning to the libraryView, the search popover is still visible. I have tried a number of different methods to remedy this: I have added a Notification observer in the segue to the search popover, posted a Notification from the search controller, posted from the entryView to the following method located in the libraryView. And, yes, libraryView does have addObserver for this method:

- (void)searchComplete:(NSNotification *)notification
{
   NSLog(@"SearchPopover dismiss notification?");
   [_searchPopover dismissPopoverAnimated:YES];
}

I have added in testing...

if (_searchPopover.popoverVisible)
{
   [_searchPopover dismissPopoverAnimated:YES];
}

To viewDidLoad, viewWillAppear, viewWillDisappear, awakeFromNib... all in the library. I have the searchPopover as a property and have tried it as an ivar. Nothing I've tried dismisses the popover before the segue or after the return.

Anyone have any ideas? Help would be much appreciated!!!

Was it helpful?

Solution

I have found a solution to this issue... found it at this answer: iOS Dismissing a popover that is in a UINavigationController

But, there was a small additional step to make... correct a typo in the answer and change the "dismissPopover" method into an NSNotification Method. I added a segue for the popover, which normally isn't necessary. The key though, is the setting of the parent's definition of the popover to the UIStoryboardPopoverSegue.

Then, use notification to let the parent know it should dismiss.

From the parent view:

- (void)viewDidLoad
{
    ... other loading code...

    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(dismissSearch:) name:@"dismissSearch" object:nil];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"SearchSegue"])
    {
        [segue.destinationViewController setDelegate:self];
        _searchPopover = [(UIStoryboardPopoverSegue *)segue popoverController];
    }
}

- (void)dismissSearch:(NSNotification *)notification
{
    NSLog(@"SearchPopover dismiss notification?");
    [_searchPopover dismissPopoverAnimated:YES];
}

In my child view (SearchView). Ideally, it would be in the didSelectRowAtIndexPath. I found it also worked in the segue to the view where it will display the searched item, which is where I would normally place an addObserver. In this case, it is a postNotification...

    [NSNotificationCenter.defaultCenter postNotificationName:@"dismissSearch" object:nil];

One last note: I was using an IBAction that checked for popover visibility when tapping the button... display or dismiss. Found that having this as well as the other method was causing the popover to dismiss immediately upon tapping the button! Commenting out the if/else check for visibility solved that!

Thanks for rdelmar for leading me on this path!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top