2015-11-29 62 views
0

我在iOS 9中使用Swift。無論我選擇哪種按鈕類型,ContactAdd除外,只會呈現信息圖標。我試圖在地圖視圖中爲標註的右側獲取DetailDisclosure圖標。代碼如下:iOS - 無法在標註中獲取按鈕的詳細信息披露

let rightButton = UIButton(type: UIButtonType.DetailDisclosure); 
    rightButton.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside) 
    annotationView.rightCalloutAccessoryView = rightButton; 

回答

0

您是否創建了一個PIN?嘗試添加該按鈕.DetailDisclosurepinView

var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? 
pinView!.rightCalloutAccessoryView = UIButton.buttonWithType(.DetailDisclosure) as UIButton 

更新 這爲我工作

let identifier = "pin" 
var view: MKPinAnnotationView 
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier) 
view.canShowCallout = true 
view.calloutOffset = CGPoint(x: -5, y: 5) 
view.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) as UIView 
+0

對不起。讓我提供整個方法。我相信該引腳正在被正確創建... – Darrell

+0

'code' func mapView(mapView:MKMapView,viewForAnnotation annotation:MKAnnotation) - > MKAnnotationView? { 讓annotationView = MKPinAnnotationView(註釋:noseyesAnnotation,reuseIdentifier:標識符) annotationView.pinTintColor = noseyesAnnotation.color annotationView.canShowCallout =真 讓rightButton =的UIButton(類型:UIButtonType.DetailDisclosure); rightButton.addTarget(self,action:「buttonTapped:」,forControlEvents:UIControlEvents.TouchUpInside) annotationView.rightCalloutAccessoryView = rightButton; 'code' – Darrell

+0

@達雷爾測試更新的代碼 –

0
@user2893289 
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? 
{ 
    let annotationView = MKPinAnnotationView(annotation: noseyesAnnotation, reuseIdentifier: "pin") 
    annotationView.pinTintColor = noseyesAnnotation.color 
    annotationView.canShowCallout = true 
    let rightButton = UIButton(type: UIButtonType.DetailDisclosure); 
    annotationView.rightCalloutAccessoryView = rightButton; 
    return annotationView 
} 
-1

@ user2893289 這仍然沒有奏效。

我試圖只是創建按鈕作爲詳細的披露,並將其添加到我的觀點和披露沒有顯示;而是顯示一個信息圖標。 這裏是簡單的代碼:

let btnview = UIButton(type: .DetailDisclosure) 

self.view.addSubview(btnview) 
相關問題