开发者

How to track where the right callout accessory view is when it was tapped on

As you can see below I have an annotation view that has a right button. When the user taps the right button I am presenting a popover - the problem is I don't know where the user tapped so I don't have the X and Y to display the popover accordingly.

How do I find out where the user tapped i.e. the X and Y?

HotelAnnotationView *customPinView = [[HotelAnnotationView alloc] initWithAnnotation:theHotel reuseIdentifier:hotelPin];

//The right button which allows user to see hotel information
UIButton* rightButton = [UIButton buttonWithType:UIButtonTy开发者_如何学CpeInfoLight];
[rightButton addTarget:self action:@selector(showDetailsForHotel:) forControlEvents:UIControlEventTouchUpInside];

rightButton.tag = theHotel.id;
customPinView.rightCalloutAccessoryView = rightButton;


Simply implement

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

Which will get called on your delegate everytime a user taps the calloutAccessoryControl. You can then access you annotation properties through

view.annotation

The reason I like this approach better than using the (id)sender is that you actually get access to not only your annotation lat & long coordinates, but any data that is actually associated with it so you can use that in your pop over view.


Your action method showDetailsForHotel: includes the sender argument, which is the button that has been tapped. You can ask it for its coordinates like any view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜