How can I display a DisclosureButton in the userLocation (the blue dot) callout like the Apple Maps app does?
Now I just can change its title and subtitle, but I hope to provide custom callout views. Therefore, if I click the blue dot, it can display a button besides only title and subtitle. In this way, when I click the button, it can guide me to another View. I returned MKAnnotationView in viewForAnnotation when annotation == self.mapView.userLocation. However, the callout can display updated title and subtitle, but cannot show the button I added.
I really need this function, and I desire any help and sugg开发者_如何学Cestion!
I've tried camdaochemgio's solution, but it works only for the second tap. Here is a solution which will always work:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView* view in views)
{
if ([view.annotation isKindOfClass:[MKUserLocation class]])
{
view.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
}
}
For the annotationView, set
myAnnotationView.canShowCallout=YES;
then add up to two buttons with
myAnnotationView.leftCalloutAccessoryView=myLeftButton;
myAnnotationView.rightCalloutAccessoryView=myRightButton;
The buttons can be a normal button, a custom button, or one of the predefined types. Like this:
myAnnotationView.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
Then add the calloutAccessoryControlTapped:
method to handle taps.
maybe late. Here is solution. You implement the UIMapViewDelegete method as below:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
if ([view.annotation isKindOfClass:[MKUserLocation class]] && !view.rightCalloutAccessoryView) {
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
}
精彩评论