我遇到了这个问题,不知道从哪里开始。
我在collectionviewcell
内添加了地图视图,并根据来自JSON的经度和纬度数据我将地图添加到地图中。我想我可以在地图上添加引脚但是当我在模拟器上运行应用程序并开始滚动列表时,根据数组大小,引脚数似乎增加了一倍或三倍。
这是我的collectionviewcell:
func configureCell(bar: Bars) {
addressDescLbl.text = bar.address
barNameLbl.text = bar.name
fb_url = bar.fb
moreInfo_url = bar.url
let location = CLLocationCoordinate2D(latitude: bar.latitude, longitude: bar.longitude)
centerMapOnLOcation(location, bar: bar)
}
func centerMapOnLOcation(location: CLLocationCoordinate2D, bar: Bars){
let span = MKCoordinateSpanMake(0.5, 0.5)
let region = MKCoordinateRegion(center: location, span: span)
self.barsMapView.setRegion(region, animated: true)
let artwork = Artwork(title: bar.name, locationName: bar.address, discipline: "scul", coordinate: location)
self.barsMapView.addAnnotation(artwork)
}
这是我的cellForItemAtIndexPath:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("BarsVC", forIndexPath: indexPath) as? BarsCell {
let currentBar: Bars!
if inSearchMode == true {
currentBar = filteredBars[indexPath.row]
}
else {
currentBar = bar[indexPath.row]
}
cell.configureCell(currentBar)
return cell
}
return UICollectionViewCell()
}
这是我的艺术作品课程:
class Artwork: NSObject, MKAnnotation {
let title: String?
let locationName:String
let discipline:String
let coordinate:CLLocationCoordinate2D
init(title: String, locationName: String, discipline: String, coordinate: CLLocationCoordinate2D) {
self.title = title
self.locationName = locationName
self.discipline = discipline
self.coordinate = coordinate
super.init()
}
var subtitle: String? {
return locationName
}
Initially the number of pins was 1 but as i scroll and come back to this cell, it gets doubled
有任何建议或想法吗?