ios - 如何从 UICollectionViewCell 呈现一个 AlertView

标签 ios uialertview uicollectionviewcell

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

我想处理核心位置错误。我有 3 种错误类型,对于其中两种,我想显示一个 UIAlertView

但是我得到一个错误,因为 UICollectionViewCell 没有名为 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 的屏幕?

最佳答案

使用窗口的 Root View Controller 来呈现警报:

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

关于ios - 如何从 UICollectionViewCell 呈现一个 AlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32390726/

相关文章:

iphone - 执行选择器 : withObject: afterDelay not executing for MBProgressHUD

xcode - 多个 UIAlertView;每个都有自己的按钮和 Action

ios - <_UIPopoverBackground VisualEffectView> 被要求为其不透明度设置动画

xcode - UICollectionViewCell 将被显示/被显示?

swift - UICollectionView 显示按钮数组 Swift

ios - UICollectionViewCell 的后台线程快照 = WebCore 崩溃

ios - 使用 Swift 和 xCode9 beta4 创建静态库

ios - 使用 Swift 多次触摸 UIButton?

ios - 如何以编程方式将支付卡添加到苹果钱包中

ios - UIAlertView 上的 EXC_BAD_ACCESS