gpt4 book ai didi

ios - SWIFT 线程 1 : EXC Bad instruction XCODE IOS

转载 作者:可可西里 更新时间:2023-11-01 02:18:07 25 4
gpt4 key购买 nike

我是 stackexchange 的新手,所以如果我需要提供更多信息,请告诉我。

我尝试安装 Corelocation 和 Mapkit 并一起使用它们。自从我遵循 Vea 软件教程以来,我一直收到以下错误:

Thread 1: EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP,subcode=0x0)

在编译器中它说

fatal error: Unexpectedly found nil while unwrapping an Optional Value(llDB)

错误出现在这一行,但是当我删除它时,它出现在另一个 Mapkit/Location 核心行。错误:

self.mapView.showsUserLocation = true

编辑:当我删除上面的行时,同样的错误出现在

 self.mapView.setRegion(region, animated: true)

我在互联网上搜索了一段时间,但没有任何帮助。感谢您的宝贵时间。

如果您需要整个 View Controller 代码。在这里。

import UIKit
import Parse
import CoreLocation
import MapKit


class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {

@IBOutlet weak var mapView: MKMapView!

let locationManager = CLLocationManager()


@IBOutlet var UsernameTextField: UITextField!
@IBOutlet var PasswordTF: UITextField!
@IBOutlet var EmailTF: UITextField!



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

self.locationManager.delegate = self

self.locationManager.desiredAccuracy = kCLLocationAccuracyBest

self.locationManager.requestWhenInUseAuthorization()

self.locationManager.startUpdatingLocation()

self.mapView.showsUserLocation = true

}






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


// MARK: - Location Delegate Methods

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last

let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)

let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))

self.mapView.setRegion(region, animated: true)

self.locationManager.stopUpdatingLocation()
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Error:" + error.localizedDescription)
}

}

最佳答案

这只是我注意到你使用的假设

self.mapView.setRegion(区域, 动画: true)

在 CLLocationManager 委托(delegate)中并在 mapView 实际显示之前开始更新(即在 viewDidLoad 中)。

会不会是 mapView 在安装到 View 层次结构之前尝试更新其视觉状态?

关于ios - SWIFT 线程 1 : EXC Bad instruction XCODE IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34730177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com