2017-02-04 3 views
0

Это код предупреждения. Проблема в том, что я хочу переходить на другой VC, когда пользователь нажимает кнопку «Ja», что означает «Да» на английском языке.Как переходить с помощью 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

Там нет необходимости вызывать 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) 
+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

Смежные вопросы