作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在开车时获取我要搜索的位置,但它给了我这个
Error Message : Thread 1: signal 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
}
}
- thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x00000001150b9d42 libsystem_kernel.dylib
__pthread_kill + 10
pthread_kill + 90 frame #2: 0x0000000114d790e7 libsystem_c.dylib
frame #1: 0x00000001150f1457 libsystem_pthread.dylibabort + 127
abort_message + 245 frame #4: 0x0000000114b0babb libc++abi.dylib
frame #3: 0x0000000114b0b91f libc++abi.dylibdefault_terminate_handler() + 265
_objc_terminate() + 97 frame #6: 0x0000000114b27159 libc++abi.dylib
frame #5: 0x000000010f9571be libobjc.A.dylibstd::__terminate(void (*)()) + 8
__cxa_rethrow + 99 frame #8: 0x000000010f9570dc libobjc.A.dylib
frame #7: 0x0000000114b26e0a libc++abi.dylibobjc_exception_rethrow + 40
CFRunLoopRunSpecific + 537 frame #10: 0x00000001155f29c6 GraphicsServices
frame #9: 0x0000000113b00a39 CoreFoundationGSEventRunModal + 62
UIApplicationMain + 159
frame #11: 0x00000001107295e8 UIKit
- frame #12: 0x000000010f038067 Map
main at AppDelegate.swift:12
start + 1 frame #14: 0x0000000114ca6d81 libdyld.dylib`start + 1 (lldb)
frame #13: 0x0000000114ca6d81 libdyld.dylib
最佳答案
我认为你需要做两个改变
第一次使用
#selector(getDirections)
代替
Selector(("getDirections"))
第二个用于 Swift 4 使用
@objc func getDirections()
代替
func getDirections()
关于ios - 将按钮连接到引脚标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47170556/
我是一名优秀的程序员,十分优秀!