我在swift中構建了一個應用程序,該應用程序在同一頁面上具有集合視圖和地圖視圖。用戶可以滾動瀏覽收藏視圖以查看優惠(這是應用的目的),並且地圖視圖中填充了註釋引腳,用於在地圖上顯示優惠的實際位置。需要幫助將mapKit註釋鏈接到Swift中的CollectionView
我的問題是,我發現很難收集觀察室鏈接到正確的註釋。
我的註釋添加到地圖如下:
for location in self.queryDataMapAnnotations {
let annotation = MKPointAnnotation()
annotation.title = location["title"] as? String
annotation.subtitle = location["distance"] as? String
annotation.coordinate = CLLocationCoordinate2D(latitude: location["latitude"] as! Double, longitude: location["longitude"] as! Double)
self.mapView.addAnnotation(annotation)
}
我則可以通過收集的滾動視圖細胞
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// get a reference to our storyboard cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MyCollectionViewCell
// Connect cell to the linked annotation
// ** This links to a random annotation, but not the correct one - need help on this please **
self.mapView.selectAnnotation(self.mapView.annotations[row], animated: true)
}
如果任何人能幫助我如何收集鏈接查看正確的地圖註釋,我會是最有幫助的。我只知道很快(一點點),所以會欣賞那種語言的幫助。由於
你的目的,突出標註時收集細胞是** **螺孔?因爲目前您在錯誤的集合視圖dataSource方法中調用'selectAnnotation()'。 – nshuman
不,用途是在用戶滾動瀏覽集合視圖時選擇註釋。因此,當用戶滾動到第1個集合視圖單元格時,會選中相應的註釋並顯示標題和副標題。然後,當用戶滾動到第二個單元格,第三個等時,這繼續下去。 –