繁体   English   中英

不知道这个xcode错误是什么意思?

[英]Don't know what this xcode error means?

我正在尝试创建用户位置地图应用,但是在运行时发生此错误:

2016-01-13 22:12:17.154 Pin My Place[1389:177444] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Pin_My_Place.ViewController 0x79fa9440> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mapview.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00624a14 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0257ee02 objc_exception_throw + 50
    2   CoreFoundation                      0x00624631 -[NSException raise] + 17
    3   Foundation                          0x00a761bc -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
    4   Foundation                          0x009d083a _NSSetUsingKeyValueSetter + 115
    5   Foundation                          0x009d07bf -[NSObject(NSKeyValueCoding) setValue:forKey:] + 295
    6   UIKit                               0x0127206d -[UIViewController setValue:forKey:] + 85
    7   Foundation                          0x00a0501d -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 384
    8   UIKit                               0x014e5cb4 -[UIRuntimeOutletConnection connect] + 132
    9   libobjc.A.dylib                     0x0259300c -[NSObject performSelector:] + 62
    10  CoreFoundation                      0x00554f51 -[NSArray makeObjectsPerformSelector:] + 273
    11  UIKit                               0x014e434e -[UINib instantiateWithOwner:options:] + 2102
    12  UIKit                               0x01279abc -[UIViewController _loadViewFromNibNamed:bundle:] + 429
    13  UIKit                               0x0127a4f4 -[UIViewController loadView] + 189
    14  UIKit                               0x0127a900 -[UIViewController loadViewIfRequired] + 154
    15  UIKit                               0x0127b1ed -[UIViewController view] + 35
    16  UIKit                               0x01128f94 -[UIWindow addRootViewControllerViewIfPossible] + 69
    17  UIKit                               0x011296b1 -[UIWindow _setHidden:forced:] + 304
    18  UIKit                               0x01129a67 -[UIWindow _orderFrontWithoutMakingKey] + 49
    19  UIKit                               0x0113d118 -[UIWindow makeKeyAndVisible] + 80
    20  UIKit                               0x010a56e7 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4190
    21  UIKit                               0x010accd6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1989
    22  UIKit                               0x010d1ee5 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3218 + 68
    23  UIKit                               0x010a9966 -[UIApplication workspaceDidEndTransaction:] + 163
    24  FrontBoardServices                  0x04921c76 __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
    25  FrontBoardServices                  0x0492174d __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
    26  FrontBoardServices                  0x0493f173 -[FBSSerialQueue _performNext] + 184
    27  FrontBoardServices                  0x0493f5aa -[FBSSerialQueue _performNextFromRunLoopSource] + 52
    28  FrontBoardServices                  0x0493e8a6 FBSSerialQueueRunLoopSourceHandler + 33
    29  CoreFoundation                      0x0053e6ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    30  CoreFoundation                      0x0053438b __CFRunLoopDoSources0 + 523
    31  CoreFoundation                      0x005337a8 __CFRunLoopRun + 1032
    32  CoreFoundation                      0x005330e6 CFRunLoopRunSpecific + 470
    33  CoreFoundation                      0x00532efb CFRunLoopRunInMode + 123
    34  UIKit                               0x010a9206 -[UIApplication _run] + 540
    35  UIKit                               0x010aebfa UIApplicationMain + 160
    36  Pin My Place                        0x000105ac main + 140
    37  libdyld.dylib                       0x044f7a21 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

码:

import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    @IBOutlet var mapView: MKMapView!
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        if CLLocationManager.locationServicesEnabled() {
            mapView.delegate = self
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyBest
            locationManager.requestAlwaysAuthorization()
            locationManager.startUpdatingLocation()
            let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "action:")
            longPressGestureRecognizer.minimumPressDuration = 0.5
            longPressGestureRecognizer.numberOfTouchesRequired = 1
            mapView.addGestureRecognizer(longPressGestureRecognizer)

        }
    }

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        mapView.setRegion(
            MKCoordinateRegion(
                center: CLLocationCoordinate2D(latitude: locations.last!.coordinate.latitude, longitude: locations.last!.coordinate.longitude),
                span: MKCoordinateSpan(latitudeDelta: 0, longitudeDelta: 0)
            ),
            animated: true
        )

    }

    func action(gestureRecognizer: UIGestureRecognizer) {
        switch gestureRecognizer.state {
        case .Began:
            let annotation = MKPointAnnotation()
            annotation.coordinate = mapView.convertPoint(gestureRecognizer.locationInView(mapView), toCoordinateFromView: mapView)
            annotation.title =  "Untitled"
            mapView.addAnnotation(annotation)
        case UIGestureRecognizerState.Changed:
            if let annotation = (mapView.annotations.filter{$0.title! == "Untitled" }).first as? MKPointAnnotation {
                annotation.coordinate =  mapView.convertPoint(gestureRecognizer.locationInView(mapView), toCoordinateFromView: mapView)
            }
        case .Cancelled:
            if let annotation = (mapView.annotations.filter{$0.title! == "Untitled" }).first as? MKPointAnnotation {
                mapView.removeAnnotation(annotation)
                // you can also prompt the user here for the annotation title
            }
        case .Ended:
            if let annotation = (mapView.annotations.filter{$0.title! == "Untitled" }).first as? MKPointAnnotation {
                let alert = UIAlertController(title: "Pin This Place", message: "", preferredStyle: UIAlertControllerStyle.Alert)
                var inputTextField: UITextField?
                alert.addAction(UIAlertAction(title: "Add", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
                    if  let annotationTitle = inputTextField?.text {
                        annotation.title =  annotationTitle
                        annotation.subtitle = "Lat:\(String(format: "%.06f", annotation.coordinate.latitude))  Lon:\(String(format: "%.06f", annotation.coordinate.longitude))"
                    }
                }))
                alert.addTextFieldWithConfigurationHandler({ textField in
                    textField.placeholder = "Place Description"
                    inputTextField = textField
                })
                alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (action) -> Void in
                    self.mapView.removeAnnotation(annotation)
                }))
                presentViewController(alert, animated: true, completion: nil)
            }
        default:
            print("default")
        }
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }


}

您的插座未连接到情节提要中。 Ctrl +左键单击情节提要中的地图视图,您应该看到mapView有一个! 而不是实心圆。 (或者您可以在右侧面板的插座检查器中查看它)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM