###前提・実現したいこと
Collection View Cell内にMKMapViewを置き、それぞれセルに一つずつ位置情報を表示する機能を作っております。しかし、Collection ViewのcellForItemAtメソッド内において位置情報をセットしているのですが、それぞれのセルのMKMapViewで、複数の位置情報のピンが立ってしまいます。
一つのセルに一つの位置情報ピンを実現するには、どうすれば良いでしょうか?
宜しくお願いします。
###該当のソースコード
UICollectionViewDataSourceを継承したView Controller
Swift
1func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 2 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.CellIdentifier, for: indexPath) as! AudioCollectionViewCell 3 let section = self.sectionCollection.sections[(indexPath as NSIndexPath).row] 4 5 let coordinate = CLLocationCoordinate2DMake(section.sectionLat, section.sectionLon) 6 let span = MKCoordinateSpanMake(0.004, 0.004) 7 let region = MKCoordinateRegionMake(coordinate, span) 8 cell.mapView.setRegion(region, animated:true) 9 10 let annotation = MKPointAnnotation() 11 annotation.title = section.sectionName 12 annotation.subtitle = section.sectionDescript 13 annotation.coordinate = CLLocationCoordinate2D(latitude: section.sectionLat, longitude: section.sectionLon) 14 cell.mapView.addAnnotation(annotation) 15 return cell 16 }
** UICollectionViewCell**
class CollectionViewCell: UICollectionViewCell { @IBOutlet weak var mapView: MKMapView! override func layoutSubviews() { super.layoutSubviews() } }
###補足情報(言語/FW/ツール等のバージョンなど)
Swift 3での実装
あなたの回答
tips
プレビュー