0
所以我有一个地图搜索功能,它有一个文本字段。我在那里设置了一个UIAlertController,它可以正常工作,即当附近没有位置时它会发出警报。虽然控制台显示活动,但按下导航栏按钮时UIAlertController不显示?
我有一个当前位置按钮,但是我只想在用户允许打开当前位置状态时执行操作。否则,我想显示警报。这是我的错误发生的地方。令人沮丧的部分是,如果未授予访问权限,我有打印语句,并且会显示该语句,并完全跳过警报。我尝试删除这些语句,只是在按钮中没有任何其他代码的情况下出现提示...仍然没有。这是怎么回事?
@IBAction func currentLocationBtn(sender: UIBarButtonItem) {
checkLocationAuthorizationStatus()
if self.locationAuthorized {
locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.currentLocation = CLLocation(latitude: locationManager.location.coordinate.latitude, longitude: locationManager.location.coordinate.longitude)
} else {
println("Current Location is disabled")
let alertController = UIAlertController(title: "Current Location Turned Off", message:
"Sorry, you need to turn on Current Location to use this feature", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
}
}
谢谢!这工作。我很困惑。我实际上有一个文本字段中的代码,它提供了另一个alertcontroller。出于某种原因,我不需要在那里展示......任何想法为什么? –
很高兴听到它的工作!如果你可以将我的答案标记为接受,那会很棒。至于其他警报控制器 - 我需要看到有问题的代码,但它们通常总是需要呈现才能显示。 –