Benutzerdefinierte callout-Ansicht mit der Taste über eine MKMapview in iOS 3.0

Ich erstellt eine Unterklasse von MKAnnotationView welche bei der gewählten Darstellung eine erläuterungsansicht (ähnlich der MKPinAnnotationView), die nur eine Unterklasse von UIView mit einem button und text für jetzt. Die callout-Komponente wird Hinzugefügt, um die annotation anzuzeigen. Das problem, das ich habe ist, dass die button, die ich in der erläuterungsansicht nie lösen keine Handlung, es scheint nicht zu reagieren auf touch-event.

Dem Grund erstelle ich eine neue MKAnnotationView ist, weil ich auf "mehr anzeigen"
als text und zwei Schaltflächen in der Beschriftungsansicht, und ich konnte nicht einen Weg finden,
zu erreichen, das mit regulären MKPinAnnotationView Legenden.

Code:

- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
    if(![annotation isKindOfClass:[CSMapAnnotation class]])
        return nil;

    CSMapAnnotation* csAnnotation = (CSMapAnnotation*)annotation;

    CustomAnnotation *customAnnotationView=[[[CustomAnnotation alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
    MKPinAnnotationView* pin = nil; pin = [[[MKPinAnnotationView alloc] initWithAnnotation:customAnnotationView reuseIdentifier:@"identifier"] autorelease];
    [pin setPinColor: MKPinAnnotationColorRed ];
    MKAnnotationView *annotationView = pin;

    annotationView.canShowCallout = YES;
    [pin setPinColor:(csAnnotation.annotationType == CSMapAnnotationTypeStart) ? MKPinAnnotationColorGreen : ((csAnnotation.annotationType == CSMapAnnotationTypeCarLocation)? MKPinAnnotationColorPurple:MKPinAnnotationColorRed) ];



    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0,0,85,25)];
    [leftView setBackgroundColor:[UIColor clearColor]];

    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareButton setBackgroundImage:[UIImage imageNamed:@"share.png"] forState:UIControlStateNormal];
    [shareButton setFrame:CGRectMake(19+GAP, 0, 25, 25)];
    [shareButton addTarget:self action:@selector(shareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [leftView addSubview:shareButton];


    UIButton *setAlertButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [setAlertButton setBackgroundImage:[UIImage imageNamed:@"alert.png"] forState:UIControlStateNormal];
    [setAlertButton setFrame:CGRectMake(shareButton.frame.origin.x+shareButton.frame.size.width+GAP, 0, 25, 25)];
    [setAlertButton addTarget:self action:@selector(alertButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [leftView addSubview:setAlertButton];


    annotationView.rightCalloutAccessoryView = leftView;
    [leftView release];

    return annotationView;
}

-(void)shareButtonAction:(id)sender {
   NSLog(@"%s",_cmd);
}

Die shareButtonAction Aktion nicht aufrufen, wenn ich Klick auf den shareButton...


Überprüfte ich oben delegieren auch, aber Es wird nicht aufgerufen, wenn installiert auf dem iPhone 3.0.. Das delegieren nennen, wenn ich nur eine Taste auf der rechten callout aber (Im obigen Fall), ist es nicht aufrufen, wenn das hinzufügen von anzeigen mit zwei Tasten. Seiner geschieht in iPhone 3.0.

InformationsquelleAutor Kathir | 2011-02-18
Schreibe einen Kommentar