简体   繁体   English

按钮标题不显示带注释

[英]Button title doesn't show with annotation

Here's my problem. 这是我的问题。 I created a red pin with a button thanks to my viewForAnnotation method.But the button doesn't show. 多亏了我的viewForAnnotation方法,我用按钮创建了一个红色的别针。但是按钮没有显示。 Here my code: 这是我的代码:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id                 <MKAnnotation>)annotation
 {
     //static NSString *defaultPinID = @"identifier";

MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"];

if ( pinView == nil )
{
    pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"identifier"];

    pinView.enabled = YES;
    pinView.pinColor=MKPinAnnotationColorRed;
    pinView.canShowCallout = YES;

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeInfoDark];
    [btn setTitle:@"test" forState:UIControlStateNormal];

    pinView.rightCalloutAccessoryView = btn;
}
else
{
    pinView.annotation = annotation;
}
pinView.annotation = annotation;

return pinView;
}

Can someone help me plz? 有人可以帮我吗?

  1. Have you added the annotation to you map? 您是否已将注释添加到地图?
  2. Have you set the MKMapView's delegate? 您设置了MKMapView的委托吗?
  3. Does your viewForAnnotation function get called? 您的viewForAnnotation函数会被调用吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM