将按钮连接到引脚标注

时间:2017-11-08 02:23:21

标签: ios swift xcode swift4

我正在尝试在驾驶时获取我正在搜索的位置,但它正在给我这个

  

错误消息:线程1:信号SIGABRT

有人可以帮忙。我正在使用Xcode9& Swift4

//Getting direction of location
        func getDirections(){
            if let selectedPin = selectedPin {
                let mapItem = MKMapItem(placemark: selectedPin)
                let launchOptions = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]
                mapItem.openInMaps(launchOptions: launchOptions)
            }
        }
extension ViewController : MKMapViewDelegate {
    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
        if annotation is MKUserLocation {
            //return nil so map view draws "blue dot" for standard user location
            return nil
        }
        let reuseId = "pin"
        var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView?.pinTintColor = UIColor.orange
        pinView?.canShowCallout = true
        let smallSquare = CGSize(width: 30, height: 30)
        let button = UIButton(frame: CGRect(origin: CGPoint.zero, size: smallSquare))
        button.setBackgroundImage(UIImage(named: "Car"), for: .normal)
        button.addTarget(self, action: Selector(("getDirections")), for: .touchUpInside)
        pinView?.leftCalloutAccessoryView = button
        return pinView
    }
}
  
      
  • 线程#1,队列=' com.apple.main-thread',停止原因=信号   SIGABRT       帧#0:0x00000001150b9d42 libsystem_kernel.dylib __pthread_kill + 10 frame #1: 0x00000001150f1457 libsystem_pthread.dylib pthread_kill + 90       帧#2:0x0000000114d790e7 libsystem_c.dylib abort + 127 frame #3: 0x0000000114b0b91f libc++abi.dylib abort_message + 245       第4帧:0x0000000114b0babb libc ++ abi.dylib default_terminate_handler() + 265 frame #5: 0x000000010f9571be libobjc.A.dylib _ objc_terminate()+ 97       帧#6:0x0000000114b27159 libc ++ abi.dylib std::__terminate(void (*)()) + 8 frame #7: 0x0000000114b26e0a libc++abi.dylib __ cxa_rethrow + 99       帧#8:0x000000010f9570dc libobjc.A.dylib objc_exception_rethrow + 40 frame #9: 0x0000000113b00a39 CoreFoundation CFRunLoopRunSpecific + 537       帧#10:0x00000001155f29c6 GraphicsServices GSEventRunModal + 62 frame #11: 0x00000001107295e8 UIKit UIApplicationMain + 159      
        
    • 第12帧:0x000000010f038067地图main at AppDelegate.swift:12 frame #13: 0x0000000114ca6d81 libdyld.dylib开始+ 1   帧#14:0x0000000114ca6d81 libdyld.dylib`start + 1   (LLDB)
    •   
  •   

1 个答案:

答案 0 :(得分:1)

我认为您需要进行两项更改

首次使用

#selector(getDirections)

而不是

Selector(("getDirections"))

第二次 Swift 4 使用

@objc func getDirections()

而不是

func getDirections()