Pregunta

Estoy usando Swift y tengo una clase llamada ViewController() que está vinculada a mi guión gráfico.Estoy intentando obtener una vista de alerta para mostrar desde otra clase.Estoy usando el siguiente código, pero no abre un cuadro de alerta.¿Algunas ideas?

public class SomeClass {

        func showAlert(title:String, body:String) {
            var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))

}
¿Fue útil?

Solución

    func showAlert(title:String, body:String) {
        var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))        
        var vc: ViewController = ViewController()
        vc.presentViewController(alert, animated: true, completion: nil)
    }

Otros consejos

tienes que llamar presentViewController en tu UIViewController y pasa en tu UIAlertViewController.

En UIViewController:

self.presentViewController(alerta, animado:verdadero, finalización:nulo)

alert siendo tu UIAlertViewController.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top