tutorial framework developer apple apis ios xcode swift

ios - framework - swift tutorial



UIAlertView en Swift, obteniendo EXC_BAD_ACCESS (3)

2 cosas que tienes que usar delegate: self cancelButtonTitle termina con nil

En primer lugar, soy bastante consciente de que Xcode 6 y el lenguaje Swift están en Beta y son propensos a errores; Sin embargo, este en particular parece ser algo extraño, ya que todo lo que he intentado hasta ahora parece funcionar bien.

Si esto no es apropiado para StackOverflow, con gusto eliminaré la pregunta.

Empecé a jugar con Xcode 6 / Swift (preparándome para su lanzamiento) y ha sido una experiencia extraordinariamente agradable en comparación con lo que pensé que sería. Dicho esto, un problema al portar una aplicación de estilo de "entrenamiento" que me gusta hacer es que parece que no puedo generar un UIAlertView debido a EXC_BAD_ACCESS el código en cuestión es:

override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) var alert = UIAlertView(title: "Title", message: "Message", delegate: nil, cancelButtonTitle: "OK") // EXC_BAD_ACCESS here alert.show() }

En la línea que crea el UIAlertView, obtengo un EXC_BAD_ACCESS porque se [UIAlertView retain] en una instancia desasignada.

Una vez más, estoy hablando de la versión beta, pero tenía curiosidad por saber si estaba haciendo algo mal o si alguien más se ha topado con problemas similares.


Desde la clase Xcode 6.0 UIAlertView:

UIAlertView está en desuso. Utilice UIAlertController con un estilo preferido de UIAlertControllerStyleAlert en su lugar.

En swift (iOS 8 y OS X 10.10), puedes hacer esto:

var alert = UIAlertController( title: "Send", message: "You have successfully send your feedback.", preferredStyle: UIAlertControllerStyle.Alert ) alert.addAction(UIAlertAction( title: "Ok", style: UIAlertActionStyle.Default, handler: nil )) self.presentViewController(alert, animated: true, completion: nil)


Prueba el siguiente código

let alert = UIAlertView() alert.title = "Title" alert.message = "My message" alert.addButtonWithTitle("Ok") alert.show()

Pero en iOS 8

UIAlertView está en desuso. Entonces use UIAlertController con un estilo preferredStyle de UIAlertControllerStyleAlert . Debería ser:

var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil)

Verifique el código anterior, ¿está recibiendo el mismo error o no?