我試圖做一個應用程序,顯示項目取決於他們的位置。不幸的是,我的代碼仍然運行,不會等到找到用戶位置。它返回一個零值。我怎樣才能避免這種情況?這是可能的,我怎麼能實現它。我的代碼如下我需要我的功能的用戶位置,但它返回無
override func viewDidLoad() {
super.viewDidLoad()
// check if locations eabled
print("I got here 1")
if CLLocationManager.locationServicesEnabled() {
self.locManager.delegate = self
self.locManager.desiredAccuracy = kCLLocationAccuracyBest
self.locManager.requestWhenInUseAuthorization()
self.locManager.startUpdatingLocation()
print("I got here 2")
}
else {
print ("Locations not enabled")
}
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pull to Refresh")
refresher.addTarget(self, action: "LoadItems", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refresher)
LoadItems()
}
我LoadItems功能要求的位置運行
選項卡上單擊符號'startUpdatingLocation()'並閱讀'Discussion' – vadian