Objective c MapView注释未显示图像和详细信息披露按钮-iOS Mapkit Xcode 6目标C

Objective c MapView注释未显示图像和详细信息披露按钮-iOS Mapkit Xcode 6目标C,objective-c,ios8,annotations,mkmapview,mapkit,Objective C,Ios8,Annotations,Mkmapview,Mapkit,我在地图视图中添加了两个注释,分别是带有图像的leftcalloutaccessoryview和带有详细信息披露按钮的RightCalloutAccessoryView。问题是它工作得很好,但只适用于一个注释,而不是两个注释。它显示一个带有图像和详细信息披露按钮的注释,可点击该按钮,而第二个注释仅显示标题、无图像和详细信息披露按钮,且无法点击。这是我的密码 -(void)viewDidLoad{ [super viewDidLoad]; myLocationManager=[[CLLoc

我在地图视图中添加了两个注释,分别是带有图像的leftcalloutaccessoryview和带有详细信息披露按钮的RightCalloutAccessoryView。问题是它工作得很好,但只适用于一个注释,而不是两个注释。它显示一个带有图像和详细信息披露按钮的注释,可点击该按钮,而第二个注释仅显示标题、无图像和详细信息披露按钮,且无法点击。这是我的密码

-(void)viewDidLoad{

 [super viewDidLoad];

 myLocationManager=[[CLLocationManager alloc] init];
 geocoder = [[CLGeocoder alloc] init];

myLocationManager.delegate=self;
myLocationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
myLocationManager.distanceFilter=10.0;
[myLocationManager startUpdatingLocation];    

mapView = [[MKMapView alloc]initWithFrame:
           CGRectMake(10, 255, 300, 205)];
mapView.delegate = self;    
mapView.centerCoordinate = CLLocationCoordinate2DMake(37.32, -122.03);    
mapView.mapType = MKMapTypeStandard; 

[self startAddingAnnottaions];

[self.view addSubview:mapView];
}
//现在就开始

-(void)startAddingAnnottaions{

//first annotation
CLLocationCoordinate2D location;
location.latitude = (double) 37.331768;
location.longitude = (double) -122.020039;
MapAnnotation *newAnnotation = [[MapAnnotation alloc]
                                initWithTitle:@"Apple Head quaters" subtitle:@"subtitle" andCoordinate:location];
[mapView addAnnotation:newAnnotation];

//second annotation
CLLocationCoordinate2D location2;
location2.latitude = (double) 37.35239;
location2.longitude = (double) -122.025919;
MapAnnotation *newAnnotation2 = [[MapAnnotation alloc]
                                 initWithTitle:@"Test Annotation" subtitle:@"parse"  andCoordinate:location2];
[mapView addAnnotation:newAnnotation2];
}
//DIDADD注释视图

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
 MKAnnotationView *annotationView = [views objectAtIndex:0];
 id <MKAnnotation> mapPoint = [annotationView annotation];

annotationView.canShowCallout = YES;
annotationView.calloutOffset = CGPointMake(0, 32);

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.rightCalloutAccessoryView = rightButton;

UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"orageSquare.png"]];
annotationView.leftCalloutAccessoryView = iconView;

MKCoordinateRegion region; 
region.center = [mapPoint coordinate];  
 MKCoordinateSpan span; 
 span.latitudeDelta = 0.0144927536;  //  0.0144927536 is equivalent to 1 mile
 span.longitudeDelta = 0.0144927536;  
 region.span = span; 

 [mv setRegion:region animated:YES];
 [mv selectAnnotation:mapPoint animated:YES]; 

}
//调用附件控制按钮

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
id <MKAnnotation> annotation = [view annotation];

NSLog(@"Right Button Pressed");
[self performSegueWithIdentifier:@"mapToOtherInfo" sender:self];
}
我做错了什么?它应该显示带有图像和细节披露按钮的多个注释。为什么它们只显示一个注释?有时第一个可以正常工作,有时第二个可以正常工作,但两者不能一起正常工作。

您应该在viewForAnnotation方法中设置leftCalloutAccessoryView和rightCalloutAccessoryView属性,而不是didAddAnnotationViews。然后可以显示这两个注释

例如:

- (MKAnnotationView *)mapView:(MKMapView*)mapView
        viewForAnnotation:(id <MKAnnotation>)annotation
{
    if (annotation == mapView.userLocation) {
        return nil;
    }

    MKPinAnnotationView *annotationView;
    NSString *identifier = @"Pin";
    annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (nil == annotationView) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
    }

    UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"frame_blue.png"]];
    annotationView.leftCalloutAccessoryView = iconView;

    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    return annotaionView;
}

它奏效了,解决了我的问题。非常感谢你。