How to present an AlertView from a UICollectionViewCell

≡放荡痞女 提交于 2019-12-01 07:04:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!