2

我正在MKAnnotationView使用以下代码为两个设置标题:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation 
{

if(([annotation isKindOfClass:[Test_flag class]])) 
{

    MKAnnotationView *pinView = nil; 

    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"PinId1";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:@"pin1"] autorelease];
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
        [pinView setImage:[UIImage imageNamed:@"flg.png"]];
        [pinView setSelected:YES animated:YES];

    } 
    else 
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}
else if(([annotation isKindOfClass:[Distance1 class]])) 
{
    MKAnnotationView *pinView = nil; 

    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"PinId4";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:@"pin4"] autorelease];

        pinView.canShowCallout = YES;
        [pinView setImage:[UIImage imageNamed:@"Circle_Grey.png"]];
        [pinView setSelected:YES animated:YES];

    } 
    else 
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

当我触摸地图时,两者MKAnnotationView都是指向的,但它们不显示标题。是什么原因?请帮我找。

4

1 回答 1

0

你错过了在课堂上写title方法。Test_flag

于 2012-08-23T08:04:36.443 回答