这是我当前的代码:
import UIKit
class classViewController: UIViewController {
// The function i want to call in other view controllers..
func alertView(title: String, message: String) {
var alert:UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
}))
self.presentViewController(alert, animated: true, completion: nil)
}
}
在另一个视图控制器中,我已经做了一个IBAction
来执行这个 alertView,我做了这个:
@IBAction func button(sender: AnyObject) {
classViewController().alertView("title", message: "message")
}
当我运行应用程序时,点击按钮后出现此错误,但没有alertView
:
警告:尝试呈现不在窗口层次结构中的视图!