0

i have an map that has a few hundred MKPointAnnotations and have been set up to have a left and right callout accessory, the issue i am having is finding a way to perform an action that is specific to that annotation

for example if someone presses a specific annotation i want to go to a new viewController that has detailed information about were the annotation is. I have setup a custom object that conforms to the MKAnnotation so all the data is contained into the annotation as such...

    @synthesize coordinate;
@synthesize _title;
@synthesize _date;
@synthesize _description;
@synthesize _coordinates;

- (CLLocationCoordinate2D)coordinate;{
    CLLocationCoordinate2D theCoordinate;
    theCoordinate.latitude = _coordinates.latitude;
    theCoordinate.longitude = _coordinates.longitude;
    return theCoordinate; 
}

- (NSString *)title {
 return _title;
}

- (NSString *)subtitle {
 return _description;
}

- (void)dealloc {
 [super dealloc];
 [_description release];
 [_date release];
 [_title release];
}

can anyone help me with this please :D

4

1 に答える 1

3

上記のコードがannotation.mであるクラス名を考えてみましょう。

あなたのviewControllerで

annotation  *annotationObject=[[annotation alloc]init];
annotationObject.title=@"Some title";
annotationObject.subTitle=@"Some subtitle";
annotationObject.coordinate=someCoordinate;
[mapView addAnnotation:annotationObject];
[annotationObject release];

上記のコードをループに入れて多くの注釈を追加するか、注釈オブジェクトを配列に入れてaddAnnotationsを使用してmapViewに追加します。

viewForAnnotationで、注釈にアクセサリボタンを追加します

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
 MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease];
    annotationView.canShowCallout = YES;
    UIButton *annotationButton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annotationView.rightCalloutAccessoryView = annotationButton;
    return annotationView;
}

ユーザーがアクセスボタンを選択すると、このデリゲートが呼び出されます

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
     //Get the specific annotation by the view.annotation.title 
     //Go to another view that has details
}
于 2010-11-24T14:09:12.667 に答える