1

Swift 1.2 の場合: 地図上の注釈にボタンを追加したいと思います。ピンを最初にタップするとユーザーのIDが表示されますが、これは機能していますが、ボタンを押すと、ユーザーを詳細ビューコントローラーに送りたいと思います。

ここここで私が探しているもののアイデアを得ることができます

これらのソリューションを適用しようとしましたが、何かが足りないと思います。これは私が探しているものの別の例です

ここに画像の説明を入力

これは私のクラス宣言です:

import UIKit
import MapKit
import CoreLocation
import Parse

class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate, UIActionSheetDelegate {

これは、ボタンで注釈を作成したいコードの一部です。

    // MARK: - Create Annotation

    func createAnnotations(point: PFGeoPoint, address: String)
    {
        println("*** this evaluates n.3 ***")
        var 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
        var 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
                    var myHomePin = MKPointAnnotation()
                    let userPoint = user["location"] as! PFGeoPoint
                    myHomePin.coordinate = CLLocationCoordinate2DMake(userPoint.latitude, userPoint.longitude)
                    myHomePin.title = user.username

 //MARK: core of the problem                   
//                    let detailButton : UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
//                    myHomePin.rightCalloutAccessoryView = detailButton
//




//                    myHomePin.subtitle = address
                    self.mapView.addAnnotation(myHomePin)
                    //                    self.closeUsersArray.append(user.username!) //MARK: Test

                }






//                    println("this is the array of users * \(self.closeUsersArray) *") //MARK: Test
            }
            else
            {
                println("Error: " + error!.localizedDescription)
            }

        })

    }

前もって感謝します!

4

1 に答える 1