2017-04-01 11 views
0

私のinfo.plstファイルにNSLocationWhenInUsageDescriptionNSLocationAlwaysUsageDescriptionが含まれています。私のコードはこのようです。locationManager代理人が動作しない

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) { 

} 
} 

入力する「LocationSelectorViewControllerを」型の値を割り当てることができません。私は私が間違って何もないと思うが、それは、このエラーに

を示す保つある「CLLocationManagerDelegateの?」

問題がどこにあるか教えていただけますか?

答えて

1

Can not type "LocationSelectorViewController"の値に "CLLocationManagerDelegate"を入力しますか?

回答: あなたLocationSelectorViewControllerクラスが採用しCLLocationManagerDelegateプロトコルに準拠する必要があります。

CLLocationManagerDelegateを下記のようにクラスに追加してください。

class LocationSelectorViewController: UIViewController, 
UISearchBarDelegate, MKMapViewDelegate, CLLocationManagerDelegate { 

代わりの

class LocationSelectorViewController: UIViewController, 
UISearchBarDelegate, MKMapViewDelegate { 
関連する問題