开发者

detailButton unable to push information over. Pushed page always have empty labels

Hi can some1 plz help me....

The problem is this: Everything seems alright.. i am able to push to another page once i tap on the detailButton. However, the page which i am able to push to is always only a view without any values passed into the labels. All my labels in the view have nothing inside.. Am i doing something wrong or any wrong concept here?

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

    BOOL isRed = NO;
    //BOOL isPurple = YES;

    if([annotation isKindOfClass:[MyAnnotation2 class]])
        isRed = YES;



    MKPinAnnotationView *pinView = nil;



    if(isRed) {
        static NSString *redPin = @"redPin";
        pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:redPin];
        if (!pinView) {
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:redPin] autorelease];
            pinView.pinColor = MKPinAnnotationColorRed;
            pinView.animatesDrop = YES;
            pinView.canShowCallout = YES;

            UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


            pinView.rightCalloutAccessoryView = detailButton;

        }

        else{
            pinView.annotation = annotation;
        }    
    }
    else {
        static NSString *greenPin = @"greenPin";
        pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:greenPin];
        if (!pinView) {
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:greenPin] autorelease];
            pinView.pinColor = MKPinAnnotationColorGreen;
            pinView.animatesDrop = NO;
            pinView.canShowCallout = YES;
            UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


            pinView.rightCalloutAccessoryView = detailButton;

        }

    }  
 开发者_Go百科   return pinView; 

}

//

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"calloutAccessoryControlTapped");

if (self.patientDetailsViewController == nil) {
    self.patientDetailsViewController = [[[PatientDetailsViewController alloc] initWithNibName:@"PatientDetailsViewController" bundle:nil] autorelease];        
} 

MyAnnotation2 *selectedObject = (MyAnnotation2 *)view.annotation;
_patientDetailsViewController.nric = selectedObject.title;
NSLog(@"%@",_patientDetailsViewController.nric);
[self.navigationController pushViewController:_patientDetailsViewController animated:YES];

}


Don't use your own target/action and tagging for the callout accessory button.

Instead, use the MKMapViewDelegate method calloutAccessoryControlTapped:. Remove the addTarget line and implement the delegate method.

In that delegate method, you can access the annotation tapped using:

MyAnnotation2 *selectedObject = (MyAnnotation2 *)view.annotation;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜