Ios 无法在MKMapView中显示多个注释接点

Ios 无法在MKMapView中显示多个注释接点,ios,ios7,mkmapview,mapkit,mkannotationview,Ios,Ios7,Mkmapview,Mapkit,Mkannotationview,我有一个存储纬度和经度值的数据库。我想遍历列表并在地图上显示它们。我写了一个条件,如果类型是atm,则注释颜色应为绿色,如果类型是branch,则应显示红色 if ([myNewArrayElement isEqualToString:@"BRANCH"]) { self.customAnnotation = [[BasicMapAnnotation alloc] initWithLatitude:[[record valueForKey:@"lat

我有一个存储纬度和经度值的数据库。我想遍历列表并在地图上显示它们。我写了一个条件,如果类型是
atm
,则注释颜色应为绿色,如果类型是
branch
,则应显示红色

if ([myNewArrayElement isEqualToString:@"BRANCH"]) {                   
    self.customAnnotation = [[BasicMapAnnotation alloc] initWithLatitude:[[record valueForKey:@"lat"]floatValue] andLongitude:[[record valueForKey:@"lon"]floatValue]] ;
    NSLog(@"Current coordinates%f%f",[[record valueForKey:@"lat"]floatValue],[[record valueForKey:@"lon"]floatValue]);
    mPinColor = @"PURPLE";

    self.customAnnotation.title = record.type;
    MKPinAnnotationView * annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:self.customAnnotation
                                                              reuseIdentifier:@"CustomAnnotation"] ;
    annotationView.canShowCallout = YES;
    mPinColor = @"";
    NSLog(@"Its Basic");
    annotationView.pinColor = MKPinAnnotationColorGreen;

    [self.mapView addAnnotation:self.customAnnotation];
    self.mapView.delegate = self;
}
else if ([myNewArrayElement isEqualToString:@"ATM"]) {
    self.normalAnnotation = [[BasicMapAnnotation alloc] initWithLatitude:[[record valueForKey:@"lat"]floatValue] andLongitude:[[record valueForKey:@"lon"]floatValue]] ;
    mPinColor = @"GREEN";
    self.normalAnnotation.title = record.type;
    MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc]initWithAnnotation:self.normalAnnotation
                                                               reuseIdentifier:@"NormalAnnotation"] ;
   annotationView.canShowCallout = YES;
   mPinColor = @"";
   NSLog(@"Its Basic");
   annotationView.pinColor = MKPinAnnotationColorGreen;
   [self.mapView addAnnotation:self.normalAnnotation];

}
我对注释的看法是

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

    NSLog(@"Length of mpincolor%d",mPinColor.length);
    MKPinAnnotationView *annotationView;
    if ([mPinColor isEqualToString:@"PURPLE"]) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomAnnotation"] ;
        annotationView.canShowCallout = NO;
        NSLog(@"Its custom");
        annotationView.pinColor = MKPinAnnotationColorPurple;
        return annotationView;
    }
    else if([mPinColor isEqualToString:@"GREEN"]) {

       annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
                                                             reuseIdentifier:@"NormalAnnotation"] ;
       annotationView.canShowCallout = YES;
       mPinColor = @"";
       NSLog(@"Its Basic");
       annotationView.pinColor = MKPinAnnotationColorGreen;

       return annotationView;
    }
    return nil;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
NSLog(@“mpincolor的长度%d”,mpincolor.Length);
MKPinAnnotationView*注释视图;
if([mPinColor isEqualToString:@“紫色”]){
annotationView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“CustomAnnotation”];
annotationView.canShowCallout=否;
NSLog(“其习惯”);
annotationView.pinColor=MKPinAnnotationColorPurple;
返回注释视图;
}
else if([mPinColor IsequalString:@“绿色”]){
annotationView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation
reuseIdentifier:@“NormalAnnotation”];
annotationView.canShowCallout=是;
mPinColor=@”;
NSLog(“其基础”);
annotationView.pinColor=MKPinAnnotationColorGreen;
返回注释视图;
}
返回零;
}

我能够正确显示针脚,但颜色显示不正确。我做错了什么?

我建议您访问此网站并从中受益
颜色属性添加到BasicMapNotation类中。在视图中查询该属性以进行说明以正确初始化pinColor。顺便说一句,在viewForAnnotation方法之外创建注释视图的代码没有多大意义,因为没有使用创建的视图