0

これは私の現在のコードです:

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を実行するために作成した他のView Controllerでは、次のようにしました。

@IBAction func button(sender: AnyObject) {
  classViewController().alertView("title", message: "message")
}

アプリを実行すると、ボタンをタップした後にこのエラーが表示されますが、次のエラーは表示されませんalertView:

警告: ウィンドウ階層にないビューで表示しようとしています!

4

1 に答える 1