Objective c 用于存储数据库URL的自定义注释属性(继承问题?)
我的注释放置在地图上,如下所示:Objective c 用于存储数据库URL的自定义注释属性(继承问题?),objective-c,cocoa-touch,mapkit,Objective C,Cocoa Touch,Mapkit,我的注释放置在地图上,如下所示: 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 ob
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];
}
但是,我无法访问view.annotation.url,这很糟糕。有没有办法获取myAnn的url值?myAnn是一个对象CustomAnnotation(其中定义了@property url之类的内容),它具有:
@interface CustomAnnotation : NSObject <MKAnnotation>
@接口自定义注释:NSObject
我希望view.annotation.url会被继承,但再看看,我并没有访问CustomAnnotation
因此,我的问题是,当单击“详细信息披露”按钮时,我可以获得注释的url吗?简单:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
CustomAnnotation *annotation = (CustomAnnotation *)view.annotation;
NSURL *selectedURL = annotation.url;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
CustomAnnotation *annotation = (CustomAnnotation *)view.annotation;
NSURL *selectedURL = annotation.url;
}