【问题标题】:How to present an AlertView from a UICollectionViewCell如何从 UICollectionViewCell 呈现 AlertView
【发布时间】:2015-09-04 05:31:29
【问题描述】:

我正在使用一个 UICollectionView,标题中有一个 Map。

我想处理核心位置错误。我有 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 的屏幕?

【问题讨论】:

  • 在那里获取父 UICollectionViewpresentViewController
  • @ILikeTau UICollectionViewUIView 的子类,而不是 UIViewController 的子类。它不知道如何presentViewController
  • 在您使用 collectionview 的 viewcontroller 中执行此操作。
  • @TheParamagneticCroissant 哎呀。我的意思是视图控制器。
  • 如何在视图控制器中实现?

标签: ios uialertview uicollectionviewcell


【解决方案1】:

使用窗口的根视图控制器来呈现警报:

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

【讨论】:

    猜你喜欢
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多