swift - 如何使用 AlertView 进行搜索?

标签 swift segue alert uialertview

这是警报的代码。问题是,当用户按下按钮“Ja”时,我想转到另一个 VC,这在英语中表示"is"。

@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)

最佳答案

无需调用带有警报的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)

关于swift - 如何使用 AlertView 进行搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42041700/

相关文章:

ios - Swift 4 - 测验应用程序随机问题

ios - 在 AppDelegate 中设置 UIButton 外观时如何更改 SafariViewController 中导航栏的色调

swift - CloudKit - 使用一种字段类型获取 5 条记录...需要 3-4 秒。为什么这么慢?

ios - 从 View Controller 到自身的 Storyboard Segue

javascript - 使用返回键关闭警报对话框将 keyup 事件发送到聚焦的输入框,导致无限循环

php - 如何使用 PHP 发送许可证到期通知?

ios - 如何使 UITextField 的行为类似于 swift 3 中的银行输入格式?

objective-c - 有一排大小相同的自定义 NSView

ios - 禁用 segue 动画

javascript - 为什么 Javascript 不能像alert()那样暂停?