小编ros*_*ose的帖子

swift ios9:尝试在不提示位置授权的情况下启动MapKit位置更新

我为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

在此输入图像描述

现在我同时设置NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription,这是行不通的. 在此输入图像描述

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)

mkmapview cllocation ios swift ios9

4
推荐指数
1
解决办法
4643
查看次数

为什么没有调用didDeselectRowAtIndexPath

调用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)

iphone uitableview tableviewcell ios

1
推荐指数
1
解决办法
1892
查看次数

标签 统计

ios ×2

cllocation ×1

ios9 ×1

iphone ×1

mkmapview ×1

swift ×1

tableviewcell ×1

uitableview ×1