开发者

pass id to calloutAccessoryControlTapped

When tabbing the accessory button, i need to pass the itemId, so i can identify the item to pass on to my detail view.

So far:

Add the annotations:

for (id row in self.detailItem) {
    Item *i = (Item *) row; 
    CLLocationCoordinate2D destination;
    destination.latitude = (double) i.latitude;
    destination.longitude = (double) i.longitude;

    //i.itemid

    MapViewAnnotation *destinationAnnotation = [[MapViewAnnotation alloc] initWithTitle: i.name andCoordinate: destination];
    [self.mapView addAnnotation: destinationAnnotation];     
    [destinationAnnotation release];
}

Add the accessory button

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotat开发者_如何学Goion
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mapView.userLocation) 
{
    static NSString *defaultPinID = @"myPin";
    pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinAnnotation == nil )
        pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

    pinAnnotation.canShowCallout = YES;

    UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinAnnotation.rightCalloutAccessoryView = infoButton;

}

return pinAnnotation;
}

find the item to pass to detail view

-(void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// get annotation details here.

NSLog(@"%@", control);
}


Add an itemid property to the MapViewAnnotation class.

When adding the annotation, set the property before calling addAnnotation:

destinationAnnotation.itemid = i.itemid;
[self.mapView addAnnotation: ...

In calloutAccessoryControlTapped, access the annotation details like this:

MapViewAnnotation *annotationTapped = (MapViewAnnotation *)view.annotation;
NSLog(@"annotationTapped.itemid = %@", annotationTapped.itemid);

(If itemid will be an int, change the %@ in the NSLog to %d.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜