嘿,我目前正在开发一款小应用程序,但我的内存使用方式很高。 该应用程序有大约200个地图注释,这些添加像
//Number: 1 Airport: Lukla - Mount Everest
let location1:CLLocationCoordinate2D = CLLocationCoordinate2DMake(AirportLat[1], AirportLong[1])
let info1 = CustomPointAnnotation()
info1.coordinate = location1
info1.title = AirportTitle[1]
info1.imageName = AirportimageName[1]
Map.addAnnotation(info1)
//Number: 2 Airport: Helgoland
let location2:CLLocationCoordinate2D = CLLocationCoordinate2DMake(AirportLat[2], AirportLong[2])
let info2 = CustomPointAnnotation()
info2.coordinate = location2
info2.title = AirportTitle[2]
info2.imageName = AirportimageName[2]
Map.addAnnotation(info2)
//Number: 3 Airport: Aspen
let location3:CLLocationCoordinate2D = CLLocationCoordinate2DMake(AirportLat[3], AirportLong[3])
let info3 = CustomPointAnnotation()
info3.coordinate = location3
info3.title = AirportTitle[3]
info3.imageName = AirportimageName[3]
Map.addAnnotation(info3)
从我这里,所以我得到了一些阵列但是由它自己创建每个注释(但所有“阵列只是逐个计数”)我确定有更好的方法来做到这一点,任何人都可以给我一些tipps如何减少这个,也许为此使用for / while? :(我没有任何工作
答案 0 :(得分:1)
枚举其中一个数组,然后创建一个注释数组。然后,您可以一次将所有注释添加到地图视图中。
var allAnnotations = [CustomPointAnnotation]()
for (index, value) in enumerate(AirportLat){
let annotation = CustomPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(AirportLat[index], AirportLong[index])
annotation.title = AirportTitle[index]
annotation.imageName = AirportimageName[index]
allAnnotations += [annotation]
}
Map.addAnnotations(allAnnotations)