2012-07-14 69 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委託鏈接到它的實現類。因此,即使方法在那裏,並且正確,委託方法從未被調用過。一旦我連接了代表,它就完美運作了。