Issue with Map Annotation and MKMapView in iOS 4.2?

前端 未结 2 1891
傲寒
傲寒 2020-12-21 06:13

I have a map view with pins that when the user selects a pin it goes to a detail screen for that pin. I also have a table view that when the user selects an item it goes to

2条回答
  •  星月不相逢
    2020-12-21 06:56

    If anyone would care to see what I am using now (and it is working) ...

    - (MKPinAnnotationView *)mapView:(MKMapView *)eMapView viewForAnnotation:(id )annotation {
    
        MKPinAnnotationView *pinView = (MKPinAnnotationView *)[eMapView dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
    
        if(pinView == nil) {
    
            pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
            pinView.frame = CGRectMake(0, 0, 25, 25);
    
        } else {
    
            pinView.annotation = annotation;
    
        }   
    
        // Set up the Right callout
        UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        myDetailButton.frame = CGRectMake(0, 0, 23, 23);
        myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    
        pinView.rightCalloutAccessoryView = myDetailButton;
    
        pinView.animatesDrop = YES;
    
        // Set to show a callout on the pin
        pinView.canShowCallout = YES;
    
        return pinView;
    }
    
    // Added this at the suggestion of aBitObvious on StackOverflow - 120810
    - (void)mapView:(MKMapView *)eMapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    
        if (view.annotation == eMapView.userLocation)
            return;
    
        if (self.showDetailView == nil) {
    
            DetailData *tmpViewController = [[DetailData alloc] initWithNibName:@"DetailData" bundle:nil];
            self.showDetailView = tmpViewController;
            [tmpViewController release];
    
        }
    
        buttonDetail = (MyCustomAnnotationClass *)view.annotation;
    
        NSMutableArray *tmpArray = [NSMutableArray arrayWithObjects: [buttonDetail getDataI], [buttonDetail getDataII], [buttonDetail getDataIII], [buttonDetail getDataIV], [buttonDetail getDataV], nil];
    
        self.showDetailView.eventData = [[NSMutableArray alloc] initWithArray:tmpArray copyItems:YES];
    
        [self.navigationController pushViewController:self.showDetailView animated:YES];
    
        [self.showDetailView.eventData release];
    
    }
    

    Thanks again!

提交回复
热议问题