Dictionary SWIFT 2:带有新页面链接的注释。
首先,是的。我知道这个问题以前被问过很多次,但似乎没有一个解决方案适合我。我想在我的注释中添加一个箭头符号,这样在我按下箭头符号后,它会打开一个新的页面,如图所示 我可以将注释添加到从检索的数组创建的地图中,但我似乎无法获取注释上的按钮,因此我无法打开新页面 到目前为止,我得到的是:Dictionary SWIFT 2:带有新页面链接的注释。,dictionary,view,annotations,mapkit,swift2,Dictionary,View,Annotations,Mapkit,Swift2,首先,是的。我知道这个问题以前被问过很多次,但似乎没有一个解决方案适合我。我想在我的注释中添加一个箭头符号,这样在我按下箭头符号后,它会打开一个新的页面,如图所示 我可以将注释添加到从检索的数组创建的地图中,但我似乎无法获取注释上的按钮,因此我无法打开新页面 到目前为止,我得到的是: func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is MKUserLocation {
//return nil
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(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
}
另外,如果我尝试调试它,func mapview的代码似乎不会运行
创建注释的代码:
func getMapAnnotations->[活动]{
变量注释:数组=活动
do {
let data = NSData(contentsOfURL: NSURL(string: "http:/URL")!)
let jsonData = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)
for anItem in jsonData as! [Dictionary<String, AnyObject>] {
let longtitudeItem = (anItem["LONGTITUDE"] as! NSString).doubleValue;
let latitudeItem = (anItem["LATITUDE"] as! NSString).doubleValue;
let name = anItem["NAME"] as! String;
let description = anItem["DESCRIPTION"] as! String;
// do something with the data retrieved:
let theSpan:MKCoordinateSpan = MKCoordinateSpanMake(0.01 , 0.01)
// let location:CLLocationCoordinate2D = mapView.userLocation.coordinate;
let location:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: latitudeItem , longitude:longtitudeItem)
let theRegion:MKCoordinateRegion = MKCoordinateRegionMake(location, theSpan)
mapView.setRegion(theRegion, animated: true)
let anotation = Activity(latitude: latitudeItem, longitude: longtitudeItem)
anotation.title = name
anotation.subtitle = description
annotations.append(anotation)
} } catch let error as NSError {
print(error)
}
return annotations }
任何帮助都将不胜感激,我快疯了
Kr,是否设置了mapView的委托?调用了viewForAnnotation方法 另请参见我的示例代码:
嗨,你能检查一下我的代码,看看你是否能找到我缺少的东西吗?我对iOS开发非常陌生,所以我相信我还有很多可以改进的地方,但现在我只想检查一下如何添加按钮和打开新视图。代码:谢谢你的帮助。嗨,它是固定的。你对我从未意识到或发现的代表的看法是正确的您必须在地图视图的故事板中添加代理。谢谢。如何使注释为地图中的每个pin打开一个具有唯一键的新页面?