如何在 XCode(iOS SDK) 中将按钮添加到注释视图 [英] How to add button to annotation view in XCode(iOS SDK)

查看:17
本文介绍了如何在 XCode(iOS SDK) 中将按钮添加到注释视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MKAnnotation 中只有标题和副标题,我没有在注释中添加任何控件.如何添加按钮?

In MKAnnotation there are just title and subtitle, and i don't add anything control to annotation. How to I add a button?

推荐答案

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

Try using following delegate method of Map View. You can set right call out accessory view as button

- (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;
}

这篇关于如何在 XCode(iOS SDK) 中将按钮添加到注释视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆