2015-09-21 3 views
0

выявляет На viewload Я цикл по некоторым данным и добавление точек точек:IOS MapKit MKPointAnnotation добавить Disclosure Button - Не показывая

for (id venue in venues) { 

     MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; 
     point.coordinate = coords here; 
     point.title = @"title" 
     point.subtitle = @"sub"; 

     [self.map addAnnotation:point]; 
    } 

То, что я пытаюсь сделать, это добавить простую кнопку раскрытия в аннотации. Я использую следующее:

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

    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"String"]; 
    if(!annotationView) { 
     annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"String"]; 
     annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    } 

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

    return annotationView; 
} 

Однако после того, как изображение загружено, точечные точки больше не отображаются. Если я удалю viewForAnnotation, все загрузится вправо, однако, конечно, у меня нет кнопки раскрытия.

Что я здесь делаю неправильно?

ответ

2

Если вы хотите добавить «ПИН» в MapView, вы должны использовать MKPinAnnotationView, а не MKAnnotationView.

- (MKAnnotationView *)mapView:(MKMapView*)mapView 
     viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    MKPinAnnotationView *annotationView = (MKPinAnnotaionView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"String"]; 
    if(!annotationView) { 
    annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"String"]; 
    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    } 
} 

раскрытие кнопка отображается.

enter image description here

+0

Спасибо за ваши мысли ... но я пытаюсь получить базовую функциональность заголовка, подзаголовка, которые приходят координаты бесплатно MKPointAnnotation для. Я просто хочу добавить к ней кнопку. – aherrick

+0

Хм, я получаю ошибки. Я скопировал метод viewForNnotation точно. Что здесь не так? Благодаря! http://i.imgur.com/61YHuqH.png – aherrick

+0

Вы загружаете в пункты, первоначально используя MKPointAnnotation? – aherrick

Смежные вопросы