2013-05-31 64 views
0

我的註解放置在地圖上像這樣(繼承問題?):自定義註釋屬性從數據庫中存儲的URL

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網址定義),其中有:

@interface CustomAnnotation : NSObject <MKAnnotation> 

我希望view.annotation.url將被繼承,但同樣好看,我不訪問CustomAnnotation

所以我的問題是,當點擊詳細披露按鈕,我可以得到註釋的網址?

回答

1

容易:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 
    CustomAnnotation *annotation = (CustomAnnotation *)view.annotation; 
    NSURL *selectedURL = annotation.url; 
} 
相關問題