我为mapView suing swift写了一个简单的例子,但是我得到了打印 Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
我将mapView添加到viewController并开始定位.我requestWhenInUseAuthorization()之前也打过电话startUpdatingLocation()
我设置了Info.plist
现在我同时设置NSLocationAlwaysUsageDescription和NSLocationWhenInUseUsageDescription,这是行不通的.

Tere是我的代码,出了什么问题?
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var locationManager: CLLocationManager?
var mapView: MKMapView?
override func viewDidLoad() {
super.viewDidLoad()
let locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = 10
locationManager.delegate = self
locationManager.pausesLocationUpdatesAutomatically = true
if CLLocationManager.locationServicesEnabled() {
let status: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if status == CLAuthorizationStatus.NotDetermined {
if …Run Code Online (Sandbox Code Playgroud) 调用didSelectRowAtIndexPath,但未调用didDeselectRowAtIndexPath.我不是为什么.我在线搜索.很多类似的问题,但我找不到答案.
这是我的桌面视图
//tableView
let tempTableView = UITableView()
tempTableView.delegate = self
tempTableView.dataSource = self
tempTableView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(tempTableView)
self.tableView = tempTableView
Run Code Online (Sandbox Code Playgroud)
这是代表
//MARK: UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.cayegoryArray[indexPath.row].isSelected = true
self.tableView?.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
self.cayegoryArray[indexPath.row].isSelected = false
self.tableView?.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)
}
Run Code Online (Sandbox Code Playgroud)
这是细胞.
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .Default
setInterface()
setLayout()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not …Run Code Online (Sandbox Code Playgroud)