Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift UIAlertController示例试用,显示错误,但不确定如何修复_Swift_Xcode7 - Fatal编程技术网

Swift UIAlertController示例试用,显示错误,但不确定如何修复

Swift UIAlertController示例试用,显示错误,但不确定如何修复,swift,xcode7,Swift,Xcode7,} 我在stackoverflow中找到了这段代码,并在Xcode 7上进行了尝试。但它在presentviewcontroller上显示错误,错误为“无法调用非函数类型'UIViewController'的值”。我打错什么了吗 谢谢错误说明了什么?我将您的代码放在单个视图控制器的viewDidload方法中,该方法工作正常。 class alert { func msg(message: String, title: String = "") { let alertView = UIA

}

我在stackoverflow中找到了这段代码,并在Xcode 7上进行了尝试。但它在presentviewcontroller上显示错误,错误为“无法调用非函数类型'UIViewController'的值”。我打错什么了吗


谢谢

错误说明了什么?我将您的代码放在单个视图控制器的
viewDidload
方法中,该方法工作正常。
class alert {
func msg(message: String, title: String = "")
{
    let alertView = UIAlertController(title: title, message: message, preferredStyle: .Alert)

    alertView.addAction(UIAlertAction(title: "Done", style: .Default, handler: nil))

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