【发布时间】:2017-09-22 10:15:47
【问题描述】:
今天我想尝试使应用程序的一部分在显示警报后仅在用户按下“是”警报按钮时才执行 segue。 为了更好地解释我,我希望应用程序会显示“你确定要回家吗?”它将有两个 Botton:“是”和“否”。如果用户按下 no 则没有任何反应,如果用户按下 yes 则应用程序执行 segue。问题是我不知道该怎么做。
我尝试编写一些代码行,但它不起作用。
func Alert (TITLE: String, MESSAGE: String) -> Bool()
{
var X = false
let Alert = UIAlertController(title: TITLE, message: MESSAGE, preferredStyle: UIAlertControllerStyle.alert)
Alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.default, handler: { (Action) in
X = true
Alert.dismiss(animated: true, completion: nil)
}))
self.present(Alert, animated: true, completion: nil)
Alert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.default, handler: nil))
self.present(Alert, animated: true, completion: nil)
return X
}
@IBAction func ButtonAct(_ sender: Any) //This happen if you click the botton on the screen of the iPhone
{
if Alert (TITLE: "Return to Home", MESSAGE: "Are you sure to return Home?")
{performSegue(withIdentifier: "Segue", sender: self)}
}
谢谢你的帮助
【问题讨论】:
标签: ios iphone swift segue alert