我有源代码这些线路实现的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;
    }

在紫色销具有细节公开键,但批注没有一个。如何设置这样的按钮?

而这正是我可以做事端的按钮的方法的pressd:

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

怎么可能我的位置和所有其他人的区别,因为我需要不同的处理方式。是否有另一种委托或做我必须做出某种如果从句?

有帮助吗?

解决方案

在您的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