2

マップキットのコールアウトに詳細開示ボタンが表示されない理由がわかりません。これが私のコードです:

.hファイルに含めてから、次のメソッドを含めるようにしました。コールアウトは機能し、マップが読み込まれた直後に表示されます。また、Xibファイルにデリゲートを接続するようにしました。

   - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *mapPin = nil;
    if(annotation != map.userLocation) 
    {
        static NSString *defaultPinID = @"defaultPin";
        mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if (mapPin == nil )
        {
            mapPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                                                     reuseIdentifier:defaultPinID];
            mapPin.canShowCallout = YES;

            UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            [disclosureButton addTarget:self action:@selector(clDetails:) forControlEvents:UIControlEventTouchUpInside];

            mapPin.rightCalloutAccessoryView = disclosureButton;

        }
        else
            mapPin.annotation = annotation;

    }
    return mapPin;
}




  - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    id<MKAnnotation> myAnnotation = [self.mapView.annotations objectAtIndex:0];
    [self.mapView selectAnnotation:myAnnotation animated:YES];
}

助けてくれてありがとう。

4

2 に答える 2

1

このコード行がviewDidLoadにあり、MKAnnotationメソッドをスローしていました。

mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];

:)

于 2012-09-03T12:49:34.347 に答える
1
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

{//ユーザーの場所の場合は、nilを返します。if([annotation isKindOfClass:[MKUserLocation class]])return nil;

// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                 initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
pinView.draggable = NO;
pinView.annotation = annotation;
pinView.draggable = YES;
pinView.enabled = YES;
pinView.exclusiveTouch = YES;
pinView.highlighted = YES;
pinView.multipleTouchEnabled = YES;
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.userInteractionEnabled = YES;

//button on the right for popup for pins
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;


 //Create and add the right button to the callout
 rightCalloutButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[pinView setRightCalloutAccessoryView:rightButton];

    [self updateAnnotation];

    [self crawlViews];

//zoom button on the left of popup for pins
UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[leftButton setTitle:annotation.title forState:UIControlStateNormal];
[leftButton addTarget:self 
               action:@selector(zoomToLocation:) forControlEvents:UIControlEventTouchUpInside];
pinView.leftCalloutAccessoryView = leftButton;

UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];

return pinView;

}

于 2012-09-03T13:35:59.863 に答える