Reputation: 9579
I have this following function implemented in my app
There are no errors at compile time. Yet I cannot see the right accessory button on my map annotations in the simulator. I see the annotation, its just that there is no button on it. Is there a trick to this that Im missing?
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id
<MKAnnotation>)annotation
{
static NSString *identifier = @"Vendor";
//Set upt the right accessory button
UIButton *myDetailAccessoryButton = [UIButton
buttonWithType:UIButtonTypeDetailDisclosure];
myDetailAccessoryButton.frame = CGRectMake(0, 0, 23, 23);
myDetailAccessoryButton.contentVerticalAlignment =
UIControlContentVerticalAlignmentCenter;
myDetailAccessoryButton.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentCenter;
[myDetailAccessoryButton addTarget:self
action:nil
forControlEvents:UIControlEventTouchUpInside];
if ([annotation isKindOfClass:[Vendor class]])
{
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView
dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil)
{
annotationView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:identifier];
annotationView.rightCalloutAccessoryView = myDetailAccessoryButton;
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.calloutOffset = CGPointMake(-5, 5);
}
else
{
annotationView.annotation = annotation;
}
return annotationView;
}
return nil;
}
EDIT This code worked but the above one doesn't.
Why is that?
if ([annotation isMemberOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:@"currentloc"];
UIButton *myDetailButton = [UIButton
buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment =
UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self
action:nil
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = myDetailButton;
annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
Upvotes: 0
Views: 984
Reputation:
Are you sure you're adding annotations of type Vendor
?
Because the first code block only sets the rightCalloutAccessoryView
for annotations of type Vendor
. For any other type, it returns nil
resulting in a generic callout (no buttons).
The second code block sets the rightCalloutAccessoryView
for any annotation type except MKUserLocation
.
By the way, you've set the button action to nil
which means nothing will happen when it's tapped.
Upvotes: 1