ios – 从UITableViewCell呈现UIAlertController

我正在尝试向自定义UITableViewCell添加警报,以呈现我需要从UIViewController调用presentViewController的UIAlertView.但是,我不知道如何从UITableViewCell类访问当前的UIViewController实例.以下代码是我尝试使用扩展程序执行此操作.

我收到这个错误

Expression resolved to unused function.

extension UIViewController
{

    class func alertReminden(timeInterval: Int)
    {
        var refreshAlert = UIAlertController(title: "Refresh", message: "All data will be lost.", preferredStyle: UIAlertControllerStyle.Alert)

        refreshAlert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action: UIAlertAction!) in
            Alarm.createReminder("Catch the Bus",
                timeInterval: NSDate(timeIntervalSinceNow: Double(timeInterval * 60)))
        }))

        refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action: UIAlertAction!) in
            println("Handle Cancel Logic here")
        }))

        UIViewController.presentViewController(refreshAlert)


    }
}

class CustomRouteViewCell: UITableViewCell {
您可以使用此扩展来查找显示单元格的viewController

extension UIView {
var parentViewController: UIViewController? {
    var parentResponder: UIResponder? = self
    while parentResponder != nil {
        parentResponder = parentResponder!.nextResponder()
        if parentResponder is UIViewController {
            return parentResponder as! UIViewController!
        }
    }
    return nil
}
}

或者使用rootViewController来呈现:

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(refreshAlert,animated:true,completion:nil)

相关文章
相关标签/搜索
精选天下彩票与你同行