使用Array Swift设置按钮标题

时间:2017-04-18 08:15:12

标签: arrays swift

我有一个谷歌地图,其中包含多个按钮作为标记,我设置了标记位置和放大器。标题使用:

self.mapView.delegate = self
let camera = GMSCameraPosition.camera(withLatitude: -7.0343237999999992, longitude: 110.42400399999997, zoom: 15)
self.mapView.animate(to: camera)

let infoWindow = Bundle.main.loadNibNamed("MapsWindows", owner: self, options: nil)?.first! as! MapsWindows

let markerView = infoWindow

for state in self.states {
    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(state.lat, state.long)
    infoWindow.titleButton.setTitle(state.name, for: .normal)
    marker.iconView = markerView
    marker.map = self.mapView

}

位置正确,但按钮的标题始终设置为最新的数组索引。所以我的所有按钮都有相同的标题。如何使按钮标题适当的顺序?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,只是把

let infoWindow = Bundle.main.loadNibNamed("MapsWindows", owner: self, options: nil)?.first! as! MapsWindows

let markerView = infoWindow

在for循环中