0

MapKit在我的应用程序中使用,我需要在一个特定的位置和另一个视图控制器中放置引脚,什么时候可以选择绘制到该引脚的路线。所以,我使用了这个很棒的教程,但我在传递信息时遇到了麻烦prepareForSegue

class Place: NSObject, MKAnnotation {
    // This class creates the map annotation who have the place's location and some information about it
    let title: String?
    let locationName: String
    let discipline: String
    let coordinate: CLLocationCoordinate2D 
    // The title and the subtitle will appear when the user touches in a pin from a specific place.
    init(title: String, locationName: String, discipline: String, coordinate: CLLocationCoordinate2D) {
        self.title = title
        self.locationName = locationName
        self.discipline = discipline
        self.coordinate = coordinate
        super.init()
    }
    // The title will be the place's name and in the subtitle will appear where is the location
    var subtitle: String? {
        return locationName
    }
}

annotation因此,在 Map 的 ViewController 中,如果用户点击此信息按钮,则当用户点击地图图钉时,我有此功能。

func mapView(mapView: MKMapView, annotationView view: MKAnnotationView,
            calloutAccessoryControlTapped control: UIControl) {

       let location = view.annotation as! Place
       let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
                           location.mapItem().openInMapsWithLaunchOptions(launchOptions)
 }

所以比我改变这个func

func mapView(mapView: MKMapView, annotationView view: MKAnnotationView,
        calloutAccessoryControlTapped control: UIControl) {
      let location = view.annotation as! Place
      let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
      performSegueWithIdentifier("GoRestaurant", sender: self)
}

因为我很伤心,我想在另一个 ViewController 中使用“openInMapsWithLaunchOptions”,它的标识符是“GoRestaurant”。所以比我prepareForSegue发送“位置”和“启动选项”

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        var showPlace: RestaurantsViewController = segue.destinationViewController as! RestaurantsViewController

        showPlace.location = location
        showPlace.launchOptions = launchOptions
}

但是,在 中RestaurantsViewController,当我尝试“导入”位置时,它不起作用。

var locationName: String = "" //ok, no error
var location: Place = () //error: Cannot convert value of type '()' to specified type 'Place'

我尝试以很多不同的方式初始化很多次,但我不知道谁来修复它。拜托,有人..救我的命,帮我解决这个问题!

4

0 回答 0