2016-01-13 2 views
1

Я пытаюсь создать карту приложение местоположения пользователя, но при запуске этого произошел ошибки:Не знаете, что означает эта ошибка xcode?

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() 
    } 


} 
+0

Можете ли вы поделиться кодом, в котором возникает ошибка? –

+4

ошибка говорит вам довольно ясно, что ваш 'Pin_My_Place.ViewController' не имеет« ключа »по имени« mapview »(попробуйте mapView, может быть?). Трассировка стека показывает, что это происходит при попытке подключить выходы вашего наконечника. –

+0

Спасибо, Брэд, он сделал трюк –

ответ

1

Вашей розетка не подключена в раскадровке. Control + Left Щелкните по карте в своем раскадровке, и вы увидите, что у вашего mapView есть! вместо заполненного круга. (Или вы можете просмотреть его в инспекторе торговых точек на правой панели) Подключите эту розетку с помощью опции + перетаскивание.

Смежные вопросы