按钮标题不显示注释

时间:2014-01-26 21:08:23

标签: ios map uibutton mkmapview mkannotation

这是我的问题。由于我的viewForAnnotation方法,我创建了一个带按钮的红色图钉。但是按钮没有显示。这是我的代码:

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

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

  1. 您是否已将注释添加到地图中?
  2. 您是否设置了MKMapView的委托?
  3. 您的viewForAnnotation函数是否被调用?