2012-07-14 73 views
0

所以我在我的应用程序的地图上有MKAnnotationViews,但是,我似乎无法获得注释来显示标注。下面有一些代码,我已经试过:MKAnnotationView标注没有出现

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

static NSString *identifier = @"Bar"; 
if ([annotation isKindOfClass:[BarLocations class]]) { 

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 
    if (annotationView == nil) { 
     annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
    } else { 
     annotationView.annotation = annotation; 
    } 

    annotationView.enabled = YES; 
    annotationView.canShowCallout = YES; 
    annotationView.animatesDrop = YES; 

//Doesn't work 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    button.frame = CGRectMake(0, 0, 23, 23); 
    annotationView.rightCalloutAccessoryView = button; 

//Doesn't work 
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
    [leftButton setTitle:annotation.title forState:UIControlStateNormal]; 
    [annotationView setLeftCalloutAccessoryView:leftButton]; 
    annotationView.canShowCallout = YES; 

//Doesn't work 

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    rightButton.frame = CGRectMake(0, 0, 15, 15); 
    [rightButton addTarget:self 
        action:@selector(showDetails:) 
      forControlEvents:UIControlEventTouchUpInside]; 
    annotationView.rightCalloutAccessoryView = rightButton; 


return annotationView; 
} 

注 - 我单独审判的每个那些 - 我只是把它们放在一起在这个岗位,以显示我已经尝试过的选项。

我在做什么错?

编辑

我想我找到了问题的一个重要组成部分:下面的方法不会被调用:

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

不过,我想MkMapView的像UITableView的。那么我怎么称呼它。我忘了分配一个代表吗?

任何帮助,将不胜感激

+0

您是否正在返回annotationView? – Philip 2012-07-14 19:09:38

+0

是 - 注释显示在我的地图上(带标题和副标题),其标注不包含 – Andrew 2012-07-14 19:21:09

+0

实际调用的委托方法,以及设置rightCalloutAccessoryView实际运行的行(通过调试器中的方法执行的步骤) ? – Anna 2012-07-14 19:27:53

回答

0

所以,问题原来是我忘记了mapView's委托链接到它的实现类。因此,即使方法在那里,并且正确,委托方法从未被调用过。一旦我连接了代表,它就完美运作了。