2017-04-01 3 views
0

Ich habe NSLocationWhenInUsageDescription und NSLocationAlwaysUsageDescription in meine Datei info.plst aufgenommen und mein Code ist wie folgt.locationManager Delegierter funktioniert nicht

import UIKit 
import MapKit 



class LocationSelectorViewController: UIViewController, 
UISearchBarDelegate, MKMapViewDelegate { 

@IBOutlet weak var locationSearchBar: UISearchBar! 
@IBOutlet weak var mapView: MKMapView! 
var selectedLoc: String? 
let locationManager = CLLocationManager() 

override func viewDidLoad() { 
    super.viewDidLoad() 
    locationManager.requestAlwaysAuthorization() 
    locationManager.delegate = self 
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters 
    locationManager.startUpdatingLocation() 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

func locationManager(manager: CLLocationManager, didupdateLocations locations: [CLLocation]) { 

} 

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) { 

} 

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { 

} 
} 

Ich glaube, ich habe nichts falsch, aber es ist halten diese Störung zeigt

Wert kann nicht vom Typ „LocationSelectorViewController“ zuweisen Typ „CLLocationManagerDelegate?“

Können Sie mir sagen, wo das Problem ist?

Antwort

1

Kann keinen Wert vom Typ "LocationSelectorViewController" zuweisen, um "CLLocationManagerDelegate?"

Am: Ihre LocationSelectorViewController Klasse muss CLLocationManagerDelegate Protokoll übernehmen und anpassen.

Fügen Sie die CLLocationManagerDelegate in Ihrer Klasse hinzu, wie unten gezeigt.

class LocationSelectorViewController: UIViewController, 
UISearchBarDelegate, MKMapViewDelegate, CLLocationManagerDelegate { 

statt

class LocationSelectorViewController: UIViewController, 
UISearchBarDelegate, MKMapViewDelegate {