Ios Swift错误EXC\U BAD\U指令
请告诉我这个密码。我是Swift新手(今天才开始)。这里有什么问题?我尝试搜索堆栈,但只找到了Objective-C解决方案Ios Swift错误EXC\U BAD\U指令,ios,swift,exc-bad-instruction,Ios,Swift,Exc Bad Instruction,请告诉我这个密码。我是Swift新手(今天才开始)。这里有什么问题?我尝试搜索堆栈,但只找到了Objective-C解决方案 class ViewController: UIViewController, CLLocationManagerDelegate { var locationManager = CLLocationManager() @IBOutlet weak var mapView: MKMapView! override func viewDidLoad() { su
class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
if (CLLocationManager.locationServicesEnabled()) {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations.last! as CLLocation
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
mapView.setRegion(region, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
您可能忘了将情节提要中的地图视图挂接到代码中的
mapView
插座上。错误在哪一行?控制台上有记录吗?`mapView.setRegion(region,动画:true)`这行顺便说一句,如果你只想让地图视图跟踪用户的位置,你所做的不是这样做的。你是说拖放吗?你知道苹果为什么没有将此作为编译错误吗?什么时候有人会从没有连接一个销售点中获益?这样可以避免每天都有人问这个问题,因为NIB不是这样工作的。在加载nib并尝试通过outlet属性引用nib实例化对象之前,我们不会知道有问题。这不是编译时,而是运行时。