问题
I am using a UICollectionView with a Map in the header.
I want to handle Core Location errors. I have 3 error types and for two of them I want to present a UIAlertView
.
But I am getting an error, because UICollectionViewCell
doesn't have a member called presentViewController
.
func locationUnknown() {
var alert = UIAlertController(title: "Location Unknown", message: "Please try again later.", preferredStyle: UIAlertControllerStyle.Alert)
let alertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> Void in
})
alert.addAction(alertAction)
self.presentViewController(alert, animated:true, completion: nil)
}
How can I send this UIAlertView
to the UICollectionView
's screen?
回答1:
Use the window's root view controller to present the alert:
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
来源:https://stackoverflow.com/questions/32390726/how-to-present-an-alertview-from-a-uicollectionviewcell