uialertcontroller怎么使用
2016-01-25
展开全部
import UIKit
class ViewController: UIViewController {
var actionString: String?
@IBAction func showAlert(sender: UIButton) {
let alertViewController = UIAlertController(title: "Test Title", message: "Message", preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
self.actionString = "OK"
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in
self.actionString = "Cancel"
}
alertViewController.addAction(cancelAction)
alertViewController.addAction(okAction)
presentViewController(alertViewController, animated: true, completion: nil)
}
}
注意,在这个例子中弹窗动作没有做什么具体的操作,他们只表示能验证单元测试。
class ViewController: UIViewController {
var actionString: String?
@IBAction func showAlert(sender: UIButton) {
let alertViewController = UIAlertController(title: "Test Title", message: "Message", preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
self.actionString = "OK"
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in
self.actionString = "Cancel"
}
alertViewController.addAction(cancelAction)
alertViewController.addAction(okAction)
presentViewController(alertViewController, animated: true, completion: nil)
}
}
注意,在这个例子中弹窗动作没有做什么具体的操作,他们只表示能验证单元测试。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询