My Annotations像这样放在地图上:
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
。
所以我的问题是,当点击详细信息披露按钮时,我可以获得注释的网址吗?
答案 0 :(得分:1)
易:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
CustomAnnotation *annotation = (CustomAnnotation *)view.annotation;
NSURL *selectedURL = annotation.url;
}