- (MKAnnotationView *)mapView没有被调用

在我的代码中,
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
方法没有被调用。我不知道为什么。谁能帮帮我吗? 以下是我的代码:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{

    MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@","];
    NSLog(@"pin map");
    if(pinView == nil) 
    {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@""];

        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;

        UIImage *image = [UIImage imageNamed:@"ann.png"];

        CGRect resizeRect;

        resizeRect.size = image.size;
        CGSize maxSize = CGRectInset(self.view.bounds,
                                     [map annotationPadding],
                                     [map annotationPadding]).size;*/
        maxSize.height -= self.navigationController.navigationBar.frame.size.height + [map calloutHeight];
        if (resizeRect.size.width > maxSize.width)
            resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
        if (resizeRect.size.height > maxSize.height)
            resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);

        resizeRect.origin = (CGPoint){0.0f, 0.0f};

        UIGraphicsBeginImageContext(resizeRect.size);
        [image drawInRect:resizeRect];
        UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        pinView.image = resizedImage;
        pinView.opaque = NO;

        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self
                        action:@selector(showDetails:)
              forControlEvents:UIControlEventTouchUpInside];
        pinView.rightCalloutAccessoryView = rightButton;

        if (annotation == mapView.userLocation)
        {

            return nil;
        }
        return pinView;

    } 
    else 
    {

        pinView.annotation = annotation;
    }

    return pinView;

}
这就是我将注释添加到地图的方式:
-(void) Annotations:(int)i
{

    /*NSString* address = [mpartyDetail objectAtIndex:i];
    address = [[address componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString: @""];
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", address];
    NSLog(@"nsstring %@",urlString);
    NSString *locationString = [[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease];
    NSLog(@"location string %@",locationString);
    NSArray *latlng = [locationString componentsSeparatedByString:@","];
    NSLog(@"the latlng %@",latlng);

    float lat = [[latlng objectAtIndex:2] floatValue];
    float lng = [[latlng objectAtIndex:3] floatValue]; */
    NSLog(@"ann");
    lat = [[latiArray objectAtIndex:i]floatValue];
    lng = [[longiArray objectAtIndex:i]floatValue]; 
    CLLocationCoordinate2D newCoord = {lat,lng};
    mapAnnotations* annotation = [[mapAnnotations alloc] initWithCoordinate:newCoord];

    [mapView addAnnotation:annotation];

}
mapAnnotations是另一个类。下面的代码显示了被调用的类的方法:
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate{

    NSLog(@"the cor");
    self = [super init];

    if (self != nil) {
        NSLog(@"in");
        _coordinate = coordinate;

    }

    return self;

}
我的想法是当用户按下地图时我添加注释,用户可以为该引脚提供任何标题。我需要一个标注来显示用户输入的标题。注释正在添加。但我无法获得标注,因为此方法未被调用。     
已邀请:
您是否将包含该方法的类指定为地图视图的委托,是否实际将任何注释添加到地图视图中,并且这些注释的位置是否在当前显示在屏幕上的地图部分中实际可见?     
正如有人正确地指出,在我的情况下,代表没有被设置为同一个班级 我所做的只是在我添加注释的代码中我编写了代码:
mapView.delegate=self;
它对我很有用。 如果你没有这样做,它也可能对你也有用droid。     
你是如何在地图上添加注释的?我使用以下内容
while(some condition){
MapAnnotation *annotation = [[MapAnnotation alloc] initWithLatitude:(float)goLat Longitude:(float)goLng title:(NSString*)recallTask.blurb subtitle:(NSString*)recallTask.location];
        [appDelegate.annArray addObject:annotation];
        [annotation release];
        annotation = nil;
    }
[self.mapView addAnnotations:appDelegate.annArray];
    

要回复问题请先登录注册