在mapview中添加按钮到注释气泡



下面是我在mapview中添加注释的代码。这段代码在viewdidload方法

中调用
-(void)displayMYMap
{
MKCoordinateRegion region = mapView.region; 
MKCoordinateSpan span; 
span.latitudeDelta=0.2; 
span.longitudeDelta=0.2; 
addAnnotation = [[[AddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:passedRecordID]autorelease];
[mapView addAnnotation:addAnnotation];
region.span=span; 
region.center=mapCenter; 
}

我正试图添加一个按钮到我的注释气泡。当我试图将按钮添加到annotationview时,我得到了一个异常。

UIButton *informationButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure ];
addAnnotation.rightCalloutAccessoryView = informationButton;

这是我写的代码来添加按钮。我想不出异常的原因

using delegate method of Annotation,

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    static NSString *identifier = @"RoutePinAnnotation";
        MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                         initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
        pinView.animatesDrop=YES;
        pinView.canShowCallout=YES;
        if ([(UICCircleAnnotation *)annotation annotationType] == UICCircleAnnotationTypeOther) {
            pinView.pinColor = MKPinAnnotationColorPurple;
        } else if ([(UICCircleAnnotation *)annotation annotationType] == UICCircleAnnotationTypeContact) {
            pinView.pinColor = MKPinAnnotationColorRed;
        }
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        [rightButton addTarget:self
                        action:@selector(buttonMethod:)
              forControlEvents:UIControlEventTouchUpInside];
        pinView.rightCalloutAccessoryView = rightButton;
        UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
        pinView.leftCalloutAccessoryView = profileIconView;
        [profileIconView release];
        return pinView;
}

在注释视图的委托方法,

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    static NSString *identifier = @"RoutePinAnnotation";
        MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                         initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
        pinView.animatesDrop=YES;
        pinView.canShowCallout=YES;
        if ([(UICCircleAnnotation *)annotation annotationType] == UICCircleAnnotationTypeOther) {
            pinView.pinColor = MKPinAnnotationColorPurple;
        } else if ([(UICCircleAnnotation *)annotation annotationType] == UICCircleAnnotationTypeContact) {
            pinView.pinColor = MKPinAnnotationColorRed;
        }
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        return pinView;
}

您将在注释气泡上获得披露按钮。

相关内容

  • 没有找到相关文章

最新更新