在我的代码中,我正在使用Apple地图并在视图控制器中正确设置mapView和委托给自己。
在我的ViewController中,我在for循环中也有以下代码:
if userOnMapAlready == false {
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: otherUserLocation.coordinate.latitude, longitude: otherUserLocation.coordinate.longitude)
annotation.subtitle = otherUserUUID
self.mapView.addAnnotation(annotation)
}
我的视图控制器中也有以下委托功能,并且再次在View Controller中设置mapview.delegate = self:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
pinView!.pinColor = .purple
}
else {
pinView!.annotation = annotation
}
return pinView
}
可悲的是,当绘制引脚时,它们都是红色的,而不是像viewForAnnotation所暗示的那样紫色。问题是什么?!是否与reuseId不匹配唯一的字幕即时分配给每个MKPointAnnotation?
UPDATE:刚刚意识到委托函数viewForAnnotation永远不会被调用 - 这可以解释为什么引脚不是紫色的。为什么viewForAnnotation不会被调用???
答案 0 :(得分:0)
在最新版本的Swift中,该属性将是:
from entity in entities
join p in persons on 1 equals 1 into groupJoin
from person in groupJoin.DefaultIfEmpty()
where person.ABA == entity.Respondent || person.ABA == entity.TierRespondent
&& person.ABA != null
select new
{
entity.Name,
entity.Respondent,
entity.TierRespondent,
person?.Name,
person?.ABA
}
...或
pinView!.pinTintColor = .purple
↳https://developer.apple.com/reference/mapkit/mkpinannotationview