如何从UICollectionViewCell呈现AlertView [英] How to present an AlertView from a UICollectionViewCell

查看:94
本文介绍了如何从UICollectionViewCell呈现AlertView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标题中使用带有Map的UICollectionView。

I am using a UICollectionView with a Map in the header.

我想处理核心位置错误。我有3种错误类型,其中两种我想呈现 UIAlertView

I want to handle Core Location errors. I have 3 error types and for two of them I want to present a UIAlertView.

但我得到的是错误,因为 UICollectionViewCell 没有名为的成员presentViewController

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)
}

如何将此 UIAlertView 发送到 UICollectionView 的屏幕?

How can I send this UIAlertView to the UICollectionView's screen?

推荐答案

使用窗口的根视图控制器显示警告:

Use the window's root view controller to present the alert:

self.window?.rootViewController?.present(alert, animated: true, completion: nil)

这篇关于如何从UICollectionViewCell呈现AlertView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆