質問

Iは、ソースコードのこれらの行で実現MKMapViewを有する(私の場所は青い弾丸、他方のの紫ピンである)

- (MKAnnotationView *)mapView:(MKMapView *)mapViewLocal viewForAnnotation:(id <MKAnnotation>)annotation {
    if (annotation == mapViewLocal.userLocation) {
        mapViewLocal.userLocation.title = @"Test";
        [mapViewLocal setRegion:MKCoordinateRegionMakeWithDistance(mapViewLocal.userLocation.coordinate, 1000, 1000) animated:YES];
        return nil;
    }

    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapViewLocal dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
        if(pinView == nil) {
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease];
            pinView.pinColor = MKPinAnnotationColorPurple;
            pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            pinView.animatesDrop = NO;
            pinView.canShowCallout = YES;
        } else {
            pinView.annotation = annotation;
        }
        return pinView;
    }

紫色のピンは、詳細開示ボタンを持っていますが、私の注釈は1を持っていません。どのように私は、このようなボタンを設定することができますか?

そして、それは私がsomethinのボタンを行うことができます方法pressdされている。

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
私は別の取り扱いを必要とするので、

どのように私は、私の場所と他のすべての1の区別があります。別のデリゲートがあるか、私はif節のいくつかの種類を確認する必要がありますか?

役に立ちましたか?

解決

タグのようなあなたのdidUpdateToLocation書き込み何かで
AddressAnnotation   *myAnnotation = [[AddressAnnotation alloc] initWithCoordinate:currentLocation];
                myAnnotation.title = @"You are here";
                [self.mapView addAnnotation:myAnnotation];

し、

何かのように

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
           // try to dequeue an existing pin view first
        static NSString* annotationIdentifier = @"annotationIdentifier";

        NSString *titlestr = annotation.title;

        MKPinAnnotationView* pinView = (MKPinAnnotationView *)
        [mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
    MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                           initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
        if (!pinView)
        {
            // if an existing pin view was not available, create one
           // MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                                   //initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease];
            if([titlestr isEqualToString:@"You are here"])
            {
                customPinView.pinColor = MKPinAnnotationColorGreen;
                NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;");
            }
            else{
                customPinView.pinColor = MKPinAnnotationColorPurple;
                customPinView.selected = TRUE;
                NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;");
                UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                [rightButton addTarget:self
                                action:@selector(ShowStoreDetail:)
                      forControlEvents:UIControlEventTouchUpInside];
                customPinView.rightCalloutAccessoryView = rightButton;
            }
            customPinView.animatesDrop = YES;
            customPinView.canShowCallout = YES;

            return customPinView;
        }
        else
        {
            pinView.annotation = annotation;



            if([titlestr isEqualToString:@"You are here"])
            {
                customPinView.pinColor = MKPinAnnotationColorPurple;
                NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;");
            }
            else{
                customPinView.pinColor = MKPinAnnotationColorPurple;
                customPinView.selected = TRUE;
                NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;");
                UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                [rightButton addTarget:self
                                action:@selector(ShowStoreDetail:)
                      forControlEvents:UIControlEventTouchUpInside];
                customPinView.rightCalloutAccessoryView = rightButton;
            }


        }
        return pinView;

    return nil;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top