MKAnnotation中只有标题和副标题,并且我不向注释添加任何控件。如何添加按钮?

最佳答案

尝试使用下面的Map View委托方法。您可以将右呼出附件视图设置为按钮

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{

MKAnnotationView *view = nil;
//MKPinAnnotationView *view=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"HotSpotsLoc"];

if(annotation !=mapView.userLocation){
    view = (MKAnnotationView *)
    [mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"];
    if(nil == view) {
        view = [[[MKAnnotationView alloc]
                 initWithAnnotation:annotation reuseIdentifier:@"identifier"]
                autorelease];
    }


    ParkPlaceMark *currPlaceMark = annotation;
    NSLog(@"%i",currPlaceMark.position);

        view.image = [UIImage imageNamed:@"pin.png"];

    UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    view.rightCalloutAccessoryView=btnViewVenue;
    view.enabled = YES;
    view.canShowCallout = YES;
    view.multipleTouchEnabled = NO;
    //view.animatesDrop = YES;

}
return view;
}

关于iphone - 如何在XCode(iOS SDK)中向注释 View 添加按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6550201/

10-09 13:01