这是警报的代码。问题是,当用户按下“Ja”按钮时,我想要转到另一个VC,这意味着“是”英文。
@IBAction func TillbakaAction(_ sender: UIButton)
{
createAlert(title: "Är du säker på att du vill börja om?", message: "Ifyllda betyg nollställs")
}
func createAlert (title:String, message:String)
{
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
//CREATING ON BUTTON
alert.addAction(UIAlertAction(title: "Ja", style: UIAlertActionStyle.default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
print ("Jag vill gå tillbaka")
}))
alert.addAction(UIAlertAction(title: "Nej", style: UIAlertActionStyle.default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
print("Nej, jag vill inte gå tillbaka")
}))
self.present(alert, animated: true, completion: nil)
答案 0 :(得分:1)
无需拨打dismiss
警报,当您按AlertController
的任何操作时,它会自动解除警报。
只需添加performSegue(withIdentifier:sender:)
即可。
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ja", style: .default, handler: { (action) in
print ("Jag vill gå tillbaka")
// call the segue at hare
self.performSegue(withIdentifier:"SegueIdentifer", sender: nil)
}))
alert.addAction(UIAlertAction(title: "Nej", style: .default, handler: { (action) in
print("Nej, jag vill inte gå tillbaka")
}))
self.present(alert, animated: true)
答案 1 :(得分:0)
@IBAction func TillbakaAction(_ sender: UIButton)
{
createAlert(title: "Är du säker på att du vill börja om?", message: "Ifyllda betyg nollställs")
}
func createAlert (title:String, message:String)
{
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
//CREATING ON BUTTON
alert.addAction(UIAlertAction(title: "Ja", style: UIAlertActionStyle.default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
print ("Jag vill gå tillbaka")
// call the segue at hare
}))
alert.addAction(UIAlertAction(title: "Nej", style: UIAlertActionStyle.default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
print("Nej, jag vill inte gå tillbaka")
}))
self.present(alert, animated: true, completion: nil)