2013-03-19 90 views
0

我们试图在iOS应用程序中实现MKMapView。我得到了具有给定位置和引脚的mapView。当我点击这些引脚时,我也得到标题和副标题。现在我想包括在这个视图中显示标题和副标题的详细信息按钮。为此,我使用了下面给出的代码[MKPinannotation详细信息公开按钮 - 呈现新视图进入第一个方法,但它没有显示detailDisclosureButton。在注释视图中不显示DetailDisclosureButton

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
    MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"]; 
    if (!pinView) { 
     pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] autorelease]; 
     pinView.pinColor = MKPinAnnotationColorRed; 
     pinView.animatesDrop = YES; 
     pinView.canShowCallout = YES; 

     UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     pinView.rightCalloutAccessoryView = rightButton; 
    } else { 
     pinView.annotation = annotation; 
    } 
    return pinView; 
} 


- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped 
{ 
} 

现在我该怎么办?任何人请看看,帮我...

+0

一旦尝试MKPinAnnotationView * pinView在.h文件中声明并使用 – 2013-03-19 06:28:50

回答

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

    pinView = nil; 
    if(annotation != map.userLocation) 
    { 
     NSString *defaultPinID [email protected]"com.invasivecode.pin1"; 
     pinView = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (pinView == nil) pinView = [[[MKPinAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; 
     UIButton *btnGo = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     [btnGo addTarget:self action:@selector(goToLocation:) forControlEvents:UIControlEventTouchUpInside]; 
     pinView.rightCalloutAccessoryView=btnGo; 
     pinView.canShowCallout = YES; 
     pinView.animatesDrop = YES; 
     pinView.draggable=NO; 
    } 
    else { 
     [map.userLocation setTitle:@"I am here"]; 
    } 
    return pinView; 
} 

声明这.h文件

MKPinAnnotationView *pinView 
+0

非常感谢你Manohar ..它工作:) :) :) – iOSiOS 2013-03-19 06:48:38

+0

:嗨马诺哈,现在我有另一个问题。当地图第二次加载时,它不显示引脚。请帮助我找到一个解决方案。我已经在下面的链接中发布了带有代码的问题。 http://stackoverflow.com/questions/16297158/annotated-pins-are-not-getting-loaded-during-reloading-of-map?noredirect=1#comment23330064_16297158 – iOSiOS 2013-04-30 13:42:02

0

请尝试设置框架rightButton即

rightButton.frame = CGRectMAke (x,y,width,height); 
+0

无需设置帧亲爱的 – 2013-03-19 06:27:08

+0

如何在没有帧的情况下添加任何内容。 – Kasaname 2013-03-19 06:27:49

+0

pinView.rightCalloutAccessoryView此自动采取查看...无需设置框架 – 2013-03-19 06:28:31