我很快乐,所以如果你可以向我解释一下那就太棒了。 我正在尝试使用地图套件构建一个应用程序,它将有大约20个不同位置的引脚。到目前为止,我已设法创建一个带注释的引脚,说明其名称,副标题和信息按钮。
现在我正在尝试获取“信息”按钮以链接到第二个UI视图。目前我只编码打印文本,如下所示:
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl){
if control == view.rightCalloutAccessoryView {
print("Button taaped ")
}
我需要知道如何链接按钮以打开我在主故事板中创建的新UI,根据单击的引脚,它将具有不同的图片,标题和描述。如果有人能够解释这一点,我会非常感激 感谢
答案 0 :(得分:0)
在两个视图控制器之间创建segue,并从storyboard再次给它一个标识符,然后在你的代码而不是print中,使用标识符函数调用执行segue并按照你在故事板中键入它的方式传递标识符字符串
答案 1 :(得分:0)
在calloutAccessoryControlTapped:
上,您可以致电:
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl){
if control == view.rightCalloutAccessoryView {
performSegue(withIdentifier: "segue for otherView identifier", sender: view)
}
您将发送annotationView以准备ForSegue。
之后,您实施方法prepareForSegue:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "segue for otherView identifier" {
let annotationView = sender as! MKAnnotationView
let otherView = segue.destinationViewController as! OtherviewController
otherView.image = annotationView.image
otherView.title = annotationView.annotation?.title
otherView.description = annotationView.annotation?.subtitle
}
}
您只需要确保在otherViewController
上您拥有了您希望从其他视图(图片,标题,说明)获得的所有属性