Question

Because i have more than one element to display at a given location in a mapview, i'd like to display a WEPopoverController in the MKMapView when a given MKPinAnnotationView has been selected.

Presenting the content, which is a tableview works fine so far. I've subclassed the MKPinAnnotationView and when the annotation view gets clicked, i call my custom presentation method.

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

      [view openCustomPopoverInFrame:self.view.frame];

      [mapView deselectAnnotation:view.annotation animated:NO];

      if (_lastAnnotationView != view) {

           [_lastAnnotationView closeCustomPopover];

           _lastAnnotationView = view;
      }
}

- (void) openCustomPopoverInFrame:(CGRect) frame {

      CGRect fromFrame = self.frame; //Pin Annotation View Frame

      WEPopoverContentViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain];
      contentViewController.delegate = self;

      WEPopoverController *viewController = [[WEPopoverController alloc] initWithContentViewController:contentViewController];
      //[viewController setPassthroughViews:[NSArray arrayWithObjects:contentViewController.view, contentViewController.tableView, nil]];

      viewController.delegate = self;

      //set the displayed content
      ....

      _myPopoverController = [viewController retain];

      [viewController presentPopoverFromRect:fromFrame inView:self.superview permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown animated:YES];

      [contentViewController release];
      [viewController release];
}

Also selecting buttons in the tableview cells work find and i get the expected response (the method gets called and the popovercontroller stays on top of the view hierarchy).

My problem is, when i click on the WEPopoverController Content (one of the table view cell, in the center, where no button is located), the tap event gets passed through to the map view and therefore hides the popover controller. What can i do, to prevent passed through tap events?

I tried several solutions e.g. set the passThroughViews and also manipulating the hitTest:withEvent: method in the WETouchableView and always return nil, but that also doesn't help me any further.

Best Nic

EDIT

I've now debugged the hitTest:withEvent: method in the WETouchableView a little more in dept and it seems, that it always returns an instance of UITableViewCellContentView, which i think should be correct so far.

EDIT

So to be a little bit more clear, i want to display a popover controller and when it gets tapped it should neighter disappear like it is the usual annotation behavior nor the underlying view should get called. It should stay on top of the view and the tap event should get caught by the table view and call the specific method (tableView:didSelectRowAtIndexpath:).

I've looked at this solution aswell, but it seems not to work for me and the underlying view (wich is the map view) gets called.

Was it helpful?

Solution

Ok, what worked for me, was to add a UIButton with a transparent background color as the first subview of the table view cell. All Tap Events on the cell now get caught by the UIButton. Btw all swipe events get caught by the table view, so at least that works fine.

To be honest, this isn't a really nice solution, but it works for me. I'd really appreciate any further suggestions!

Best Nic

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