【发布时间】:2016-05-04 10:22:06
【问题描述】:
我正在尝试在每个注释视图中创建一个按钮,以将用户带到自定义所选注释的新页面。我已经成功实现了 mapview 来显示带有从我的解析数据库加载的标题和副标题的注释,但我正在努力寻找一种方法 1)在注释视图中添加一个按钮以将用户带到一个新视图 2)找到一种方法选择时为每个注释创建自定义视图。任何帮助将不胜感激?
代码
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
var MapViewLocationManager:CLLocationManager! = CLLocationManager()
let btn = UIButton(type: .DetailDisclosure)
override func viewDidLoad() {
super.viewDidLoad()
mapView.showsUserLocation = true
mapView.delegate = self
MapViewLocationManager.delegate = self
MapViewLocationManager.startUpdatingLocation()
mapView.setUserTrackingMode(MKUserTrackingMode.Follow, animated: true)
}
override func viewDidAppear(animated: Bool) {
let annotationQuery = PFQuery(className: "Clubs")
annotationQuery.findObjectsInBackgroundWithBlock {
(clubs, error) -> Void in
if error == nil {
// The find succeeded.
print("Successful query for annotations")
// Do something with the found objects
let myClubs = clubs! as [PFObject]
for club in myClubs {
//data for annotation
let annotation = MKPointAnnotation()
let place = club["location"] as? PFGeoPoint
let clubName = club["clubName"] as? String
let stadiumName = club["stadium"] as? String
annotation.title = clubName
annotation.subtitle = stadiumName
annotation.coordinate = CLLocationCoordinate2DMake(place!.latitude,place!.longitude)
//add annotations
self.mapView.addAnnotation(annotation)
}
} else {
// Log details of the failure
print("Error: \(error)")
}
}
}
【问题讨论】:
-
一个选项是在选定的注释上添加 uipopover(如果是 iPad)或客户弹出视图。您可以根据需要自定义弹出项。
标签: ios swift parse-platform annotations mapkit