【发布时间】:2015-11-30 01:27:48
【问题描述】:
我想从 MapView 上的 MKPointAnnotation 中获取信息并将其发送给下一个 VC。
如果我点击一个图钉,会出现气泡,显示一个名称和一个披露按钮,但点击该按钮我想将特定的 PFUser 传递给下一个 vc(可能来自self.testArrayUsers)
我不知道如何从地图上的大头针索引数组。提前感谢您的帮助。
我尝试通过子类化 MKPointAnnotation
import UIKit
import Parse
import MapKit
import CoreLocation
class MyMKPA: MKPointAnnotation {
var pointAnnotationPFUser = PFUser()
}
为了在下面调用它,在 func 的 2/2 点上,获取 var selecteUserOnMapByTouchgPinVar 并将其传递给 prepareForSegue
//MARK: this is for adding info button to pins on map 1/2
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
var view = mapView.dequeueReusableAnnotationViewWithIdentifier("AnnotationView Id")
if view == nil{
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "AnnotationView Id")
view!.canShowCallout = true
} else {
view!.annotation = annotation
}
view?.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure)
return view
}
//MARK: this is for adding info button to pins on map 2/2
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if (control as? UIButton)?.buttonType == UIButtonType.DetailDisclosure {
// let selectedAnnTitle = mapView.selectedAnnotations[0].title!
// self.choosenUsername = selectedAnnTitle
//*****************************************************
//this is what I had in mind, but I'm doing it very wrong, I think.
self.selecteUserOnMapByTouchgPinVar = mapView.selectedAnnotations[0].pointAnnotationPFUser
//*****************************************************
mapView.deselectAnnotation(view.annotation, animated: false)
// performSegueWithIdentifier("testFromMapToUser", sender: view) //showListDetailView
}
}
在这个 PFQuery 中,我在每个 MKPointAnnotation 中添加了一个 PFUser
func createAnnotations(point: PFGeoPoint, address: String)
{
let query = PFUser.query()
query?.whereKey("location", nearGeoPoint: point, withinKilometers: withinKms)
query?.orderByAscending("location") //MARK: Put list in order
//MARK: Not include current user on the map
let me = PFUser.currentUser()?.username
query?.whereKey("username", notEqualTo: me!)
query?.limit = self.kLimitNumberForQueryResults
query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if error == nil
{
for(var i = 0; i < objects!.count; i++) {
let user = objects![i] as! PFUser
self.testArrayUsers.append((pickedUser : user, Name : user.username!)) //I would like to use this fot button in pin
// let myHomePin = MKPointAnnotation() //switched to MyMKPA
let myHomePin = MyMKPA()
let userPoint = user["location"] as! PFGeoPoint
myHomePin.coordinate = CLLocationCoordinate2DMake(userPoint.latitude, userPoint.longitude)
myHomePin.title = self.checkAndFindName(user)//user.username
// myHomePin.subtitle = address //problem : gives always my address, not retrived users' one
myHomePin.pointAnnotationPFUser = user
self.mapView.addAnnotation(myHomePin)
// self.closeUsersArray.append(user.username!) //MARK: Test
}
// println("this is the array of users * \(self.closeUsersArray) *") //MARK: Test
}
else
{
print("Error: " + error!.localizedDescription)
}
})
}
【问题讨论】:
标签: ios swift parse-platform