如何添加几个注释?

时间:2015-11-17 21:45:30

标签: ios swift mapkit mkannotation

我想在地图视图中显示几个图钉。所以我这样做:

let smth = [Smth(title: "Title 1", 
        locationName: "Street 1", 
        coordinate: CLLocationCoordinate2D(latitude: 43.2345965, longitude: 76.8907758)),
    Smth(title: "Title 2", 
        locationName: "Street 2",
        coordinate: CLLocationCoordinate2D(latitude: 43.2059723, longitude: 76.9012738))]

然后:

mapView.addAnnotation(smth)

但是它显示了这个错误:

        Argument type '[Smth]' does not conform to expected type 'MKAnnotation'.

我该怎么办? 感谢。

1 个答案:

答案 0 :(得分:3)

解决了这个问题:

mapView.addAnnotations(smth)

阵列需要方法" addAnnotations" ,而不是" addAnnotation"