我在我的应用程序中实现了以下功能
编译时没有错误。然而,我在模拟器中的地图注释上看不到正确的附件按钮。我看到注释,只是上面没有按钮。我错过了这个技巧吗?
- (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;
}
编辑此代码有效,但上述代码无效。
这是为什么?
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;