如何在 UITableViewCell 中使用 UIAlertController

How to use UIAlertController inside UITableViewCell

如何在 TableViewCell 中使用 UIAlertController?

给我一个错误 does not have a member called "presentViewController"

我的 TableViewController 名为 "OrdensCompraTableViewController"

我的函数:

@IBAction func telefonarCliente(sender: AnyObject) {

    var alert = UIAlertController(title: "Fotos em falta!", message: "Tem de introduzir 6 fotos.", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))


    self.presentViewController(alert, animated: true, completion: nil)

    if let phoneCallURL:NSURL = NSURL(string: "tel://") {
        let application:UIApplication = UIApplication.sharedApplication()
        if (application.canOpenURL(phoneCallURL)) {
            application.openURL(phoneCallURL);
        }
    }
}

您不能从 UITableViewCell(它不是视图控制器)呈现 UIViewController。您有两个选择:

1 - 将委托分配给 UITableViewCell 指向其父视图控制器并在视图控制器上预设警报。

2 - 在应用程序的根视图控制器上显示警报:

UIApplication.sharedApplication().delegate?.window??.rootViewController?.presentViewController(alert, animated: true, completion: nil)

在拨打 phone 号码之前使用 telprompt://123456789 而不是创建 UIAlertController 来提示用户。