2017-02-04 6 views
0

これはアラートのコードです。問題は、ユーザーが「はい」を意味するボタン「Ja」を押したときに別のVCにセグをしたいということです。AlertViewとのつながり方は?

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

答えて

1

あなたがAlertControllerのいずれかのアクションを押したときに自動的に警告を閉じますアラートにdismissを呼び出す必要はありません。

あなたの行動に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) 
+0

私はあなたなしで何をしますか?ありがとう – theswed

+0

@theswedようこそメイト:) –

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) 
+0

ありがとうございました – theswed

関連する問題