我从xib文件创建了一个自定义信息窗口,并将其放入此func中:
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let infoWindow = Bundle.main.loadNibNamed("InfoWindowMap", owner: self.view, options: nil)!.first! as! InfoWindowMap
infoWindow.label.text = marker.title // it works but takes information from my marker, but i want take data from, array screenPlaces
print(screenPlaces.count) =// i want to call an array what i need, but it's empty
return infoWindow
}
我的数组screenplaces
稍后会在我连接到API时附加:
if status == "success"{
for (_,subJson):(String, JSON) in json["data"]["services"] {
let id = subJson["id"].intValue
let name = subJson["name"].stringValue
let icon = subJson["icon"].stringValue
let adress = subJson["address"].stringValue
let latitude = subJson["latitude"].stringValue
let longitude = subJson["longitude"].stringValue
self.screenPlaces.append(ScreenData(name:name, id:id,adress:adress,icon:icon, latitude: latitude, longitude: longitude))
for i in self.screenPlaces{
let position = CLLocationCoordinate2D(latitude: Double (i.latitude)!, longitude: Double( i.longitude)!)
let marker = GMSMarker(position: position)
marker.map = self.mapView
marker.title = (i.name)
marker.snippet = (i.adress)
}
}
事实证明,在添加数组之前,我先从数组中调用信息。
如果我将函数func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker)
放在if status == "success"{}
下方,则它不起作用,我看不到al的数组计数。
我该如何解决?