0

我的注释被放置在地图上,如下所示:

for (i = 0; i < [results count]; i++) {
        // create new object CustomAnnotation
        myAnn = [[CustomAnnotation alloc] init];
        // set the lat and long of the object
        location.latitude = (double)[[[results objectAtIndex:i] objectForKey:@"lat"] doubleValue];
        location.longitude = (double)[[[results objectAtIndex:i] objectForKey:@"long"] doubleValue];
        // set properties of the object
        myAnn.coordinate = location;
        myAnn.title = [[results objectAtIndex:i] objectForKey:@"title"];
        myAnn.subtitle = [[results objectAtIndex:i] objectForKey:@"strap"];
        myAnn.pinId = [[results objectAtIndex:i] objectForKey:@"id"];
        myAnn.url = [[results objectAtIndex:i] objectForKey:@"link"];
        myAnn.dateTime = [[results objectAtIndex:i] objectForKey:@"timestamp"];

        // add the object to the array locations
        [locations addObject:myAnn];
    }

在我的方法中,calloutAccessoryTapped我试图获取 myAnn.url 值,以便可以在 Safari 中打开它。这样做的方法:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    NSString *annTitle = view.annotation.title;
    NSLog(@"hello %@", annTitle);
}

但是我无法访问很糟糕的 view.annotation.url。有没有办法获取 myAnn 的 url 值?myAnn 是一个对象 CustomAnnotation(其中定义了 @property url 之类的东西),它具有:

@interface CustomAnnotation : NSObject <MKAnnotation>

我希望 view.annotation.url 会被继承,但再看一遍,我没有访问CustomAnnotation.

所以我的问题是,当点击详细信息披露按钮时,我可以获得注释的 url 吗?

4

1 回答 1

1

简单的:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    CustomAnnotation *annotation = (CustomAnnotation *)view.annotation;
    NSURL *selectedURL = annotation.url;
}
于 2013-05-31T10:37:24.020 回答