2013-03-19 88 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