gpt4 book ai didi

Swift Parse MapView 不显示 CalloutAccessory 和 Segueing

转载 作者:行者123 更新时间:2023-11-30 11:42:54 25 4
gpt4 key购买 nike

我目前有一个 UIMapView,其中为 map 上用户的不同位置固定了不同的注释。单击注释时,我试图转到相应的用户配置文件。这是我设置注释的代码:

let query = PFQuery(className: "location")

query.findObjectsInBackground { (objects, error) in

if let brandsLocation = objects {

for object in brandsLocation {

if let brandLocation = object as? PFObject {

let annotation = MKPointAnnotation()

let annotationPoint = object["geoPoint"] as! PFGeoPoint

annotation.coordinate = CLLocationCoordinate2DMake(annotationPoint.latitude, annotationPoint.longitude)

annotation.title = brandLocation["annotationTitle"] as? String

annotation.subtitle = brandLocation["annotationSubtitle"] as? String

self.map.addAnnotation(annotation)
}
}
}
}

这是我认为应该发生转场的地方,但由于某种原因它没有做任何事情。

// When user taps on the disclosure button you can perform a segue to navigate to another view controller
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {

if control == view.rightCalloutAccessoryView{

performSegue(withIdentifier: "goToUserProfile", sender: view)

print(view.annotation?.title) // annotation's title

print(view.annotation?.subtitle) // annotation's subttitle

//Perform a segue here to navigate to another viewcontroller
// On tapping the disclosure button you will get here
}
}


// Here we add disclosure button inside annotation window
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {

print("viewForannotation")
if annotation is MKUserLocation {
//return nil
return nil
}

let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView

if pinView == nil {
//println("Pinview was nil")
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
}

let button = UIButton(type: UIButtonType.detailDisclosure) as UIButton // button with info sign in it

pinView?.rightCalloutAccessoryView = button

return pinView
}

我希望在单击或双击注释时发生转场,然后在发送特定用户名信息的同时对新 View Controller 执行转场。我很确定我能够发送用户信息,但我只需要弄清楚如何进行转场。我认为这可能与新的 XCode 更新中我的 calloutaccessory 尚未显示有关。这是我的应用程序的屏幕截图。 MapView Annotation

最佳答案

使用didSelect方法代替calloutAccessoryControlTapped怎么样?

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
performSegue(withIdentifier: "goToUserProfile", sender: view)
print(view.annotation?.title) // annotation's title
print(view.annotation?.subtitle) // annotation's subttitle
}

关于Swift Parse MapView 不显示 CalloutAccessory 和 Segueing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49143057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com