1
不知道爲什麼這不工作?任何幫助將不勝感激。 Thnks。爲什麼我得到致命錯誤:意外地發現零,而解包可選值...這裏是我的代碼:
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var locationManager:CLLocationManager!
@IBOutlet weak var mapView: MKMapView!
@IBAction func nowButton(sender: AnyObject) {
}
@IBOutlet weak var mapLabel: UILabel!
@IBAction func bookButton(sender: AnyObject) {
}
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
locationManager.startUpdatingLocation()
mapView.showsUserLocation = true
mapView.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
let regionToZoom = MKCoordinateRegionMake(manager.location.coordinate, MKCoordinateSpanMake(0.05, 0.05))
mapView.setRegion(regionToZoom, animated: true)
}
}
哪條線給你錯誤? – 2015-02-09 07:27:46
除了上面所有的'IBOutlet's連接? – Rich 2015-02-09 07:37:34