ios - 如何从每个注释 View 创建自定义标注按钮?

标签 ios swift parse-platform annotations mapkit

我尝试在每个注释 View 中创建一个按钮,将用户带到根据所选注释自定义的新页面。我已经成功实现了 map View 来显示带有从解析数据库加载的标题和副标题的注释,但正在努力寻找一种方法 1) 在注释 View 中添加按钮以将用户带到新 View 2) 寻找一种方法为每个选定的注释创建自定义 View 。任何帮助将不胜感激?

代码

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)")
            }
        }

    }

最佳答案

对于第一个 - 您可以在 annoationView 上使用 leftCalloutAccessoryView 和 rightCalloutAccessoryView。您必须实现 MapViewDelegate mapView(_:viewForAnnotation:)。

对于第二个 - 与calloutAccessoryView类似,您可以访问annoationView上的detailCalloutAccessoryView。您可以使用它来自定义标注。

关于ios - 如何从每个注释 View 创建自定义标注按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35037827/

相关文章:

swift - SQLite数据库错误: The FMDatabase <FMDatabase: 0x6080000a96c0> is not open.

ios - 使用 Parse 时关闭 iOS 中的登录屏幕

ios - Parse.com saveEventually with callback 并使用 NSCache 存储数据

ios - swift 4 : back button in SWRevealViewController

ios - 如何检查框架是否支持 Xcode7 的 Bitcode

ios - 如何将自定义类分配给 TableViewController

swift - 解析账户显示

ios - 手动隐藏搜索栏 Controller

swift - 如何用可选方法包装协议(protocol)?

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?