【发布时间】:2018-08-18 23:35:31
【问题描述】:
您好,我想在用户点击注释时获取索引号。我有以下代码..
class ShopLocation: NSObject, MKAnnotation{
var identifier = "Shop location"
var title: String?
var subtitle: String?
var coordinate: CLLocationCoordinate2D
init(name:String,lat:CLLocationDegrees,long:CLLocationDegrees,addInfo:String){
title = name
coordinate = CLLocationCoordinate2DMake(lat, long)
subtitle = addInfo
}
}
class LocationList: NSObject {
var shop = [ShopLocation]()
override init(){
shop += [ShopLocation(name:"t1", lat:35.673647,long:139.727686,addInfo:"info")]
shop += [ShopLocation(name:"t2", lat:35.671928,long:139.760815,addInfo:"info")]
shop += [ShopLocation(name:"t3", lat:35.713232,long:139.793467,addInfo:"info")]
}
注释显示在地图上。我想获取索引,例如,如果点击 t1,我得到的索引为 1。
不知道写什么
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
LocationList().shop.index(of: )
}
谢谢!
【问题讨论】:
-
您需要索引还是需要访问映射到注解视图的
ShopLocation实例? -
感谢您的评论。我需要商店数组的索引。
标签: ios swift mapkit mapkitannotation