2016-11-05 8 views

答えて

1

、新しいUIAlertControllerを作成し、この例では、iOS版についての素晴らしい記事を提供していますNSHipsterのウェブサイトから取られたことを、次の

let alertController = UIAlertController(title: "Default Style", message: "A standard alert.", preferredStyle: .Alert) 

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in 
    // ... 
} 
alertController.addAction(cancelAction) 

let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in 
    // ... 
} 
alertController.addAction(OKAction) 

self.presentViewController(alertController, animated: true) { 
    // ... 
} 

ノートのようにそれを表示します。 UIAlertController hereに関する記事があります。また、例えば、アクションシートを表示するなど、そのクラスでできることを説明します。

0

スウィフト4
必要なパラメータの引数に警告表示するように機能付きのUIViewControllerの拡張を作成します

extension UIViewController { 

     func displayalert(title:String, message:String) { 
     let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) 
     alert.addAction((UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in 

      alert.dismiss(animated: true, completion: nil) 

     }))) 

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


     } 
} 


は、今すぐあなたのビューコントローラからこの関数を呼び出す:

class TestViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.displayalert(title: <String>, message: <String>) 
    } 
} 
関連する問題