How to Display a Uipopoverview as a Annotation to the Map View? (iPad)

How do I display a UIPopoverView as a annotation to the map view? (iPad)

First add an annotation to the map and in the viewForAnnotation method, set the rightCalloutAccessoryView to a button of type, say, UIButtonTypeDetailDisclosure (I don't think the blue info button is available by default).

Pressing the button will call the calloutAccessoryControlTapped delegate method. In this method, deselect the annotation and show your popover. For example:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[mapView deselectAnnotation:view.annotation animated:YES];

YourContentViewController *ycvc = [[YourContentViewController alloc] init...
UIPopoverController *poc = [[UIPopoverController alloc] initWithContentViewController:ycvc];
[ycvc release];

//hold ref to popover in an ivar
self.annotationPopoverController = poc;

//size as needed
poc.popoverContentSize = CGSizeMake(320, 400);

//show the popover next to the annotation view (pin)
[poc presentPopoverFromRect:view.bounds inView:view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

[poc release];
}

YourContentViewController is a subclass of UIViewController which you can code like any other view controller. The Maps app looks like it has UITableView in the content.

Placing arrow of uipopovercontroller at annotation point on mapkit

Okay,

Here is what I found as the only work-around so far:

CGPoint annotationPoint = [mapView2 convertCoordinate:view.annotation.coordinate toPointToView:mapView2];
float boxDY=annotationPoint.y;
float boxDX=annotationPoint.x;
CGRect box = CGRectMake(boxDX,boxDY,5,5);
UILabel *displayLabel = [[UILabel alloc] initWithFrame:box];


[popoverControllerDetail presentPopoverFromRect:displayLabel.frame inView:mapView2 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[displayLabel release];

The bad part about this is that I am faking putting it at the view of the annotation. I simply get the annotation.coordinate of the annotation view (MKMapKit style coordinates) and convert the coordinates to screen coordinates. Then I create a uilabel (to get a frame-capable construct on the screen) placed where the Annotation View would be. I then tell the popovercontroller to appear at that frame location.

Here is the kicker. I do not add the uilabel to the mapView2. I simply release it once popovercontroller has drawn itself.

Hack, but clean.

Annotation view similar to iPad Maps application

Well, here's how to show the table + popover: https://stackoverflow.com/a/5583505/394504

And here's a cocoa control that does what I want: http://www.cocoacontrols.com/platforms/ios/controls/gikanimatedcallout

Show custom view after clicking on point Annotation iOS

you can do this like describe here

stack overflow questions

one

two

How can I change the anchor point of the UIPopover? PresentFromRect doesn't work correctly for me.

Thanks Anna. Apologies for the duplicate posting - had a bit of trouble with the Stackoverflow markup.

I was using segues to launch the popover - therefore I couldn't position the popover correctly.

I believe that the workaround I used is appropriate for positioning the popover if you are using segues.

Having said that, I am now using the method suggested by your answer.

I launch the popover using

self.detailsPopover = [[self storyboard] instantiateViewControllerWithIdentifier:@"identifierName"];

//... config code for the popover

UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:detailsPopover];

//... store popover view controller in an ivar

[self.annotationPopoverController presentPopoverFromRect:selectedAnnotationView.bounds inView:selectedAnnotationView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

iOS Mapkit Custom Callout

Found out the answer after a few mins of nap.

using this as the guide, I just needed to override

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

which shows the annotation callout. Thanks again for the answer, Ms. Anna.



Related Topics



Leave a reply



Submit