2017-02-04 4 views
0

Ceci est le code de l'alerte. Le problème est que je veux segue à un autre VC lorsque l'utilisateur appuie sur le bouton "Ja" qui signifie "Oui" En anglais.Comment se connecter avec 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) 

Répondre

1

Il n'y a pas besoin d'appeler dismiss avec alerte il rejettera automatiquement l'alerte lorsque vous appuyez sur une action de AlertController.

Alors ajoutez simplement performSegue(withIdentifier:sender:) avec votre action.

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

Que ferais-je sans vous. Merci – theswed

+0

@theswed Bienvenue mec :) –

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

Cela a fonctionné merci – theswed