I can not use uialertcontroller in a uicollectionviewcell

0

I am trying to execute an action with alert in my cell, but nothing happens

  @IBAction func btneliminar(sender: AnyObject) {

    let alert = UIAlertController(title: "Eliminar", message: "Esta a punto de eliminar una cancion", preferredStyle: .Alert)
    let action = UIAlertAction(title: "Si", style: .Default, handler: {(action) in
        let cancion: Cancion = DataBaseManager.sharedInstance.getSongByKey( "id", value: Int(self.lblid.text!)!)
    DataBaseManager.sharedInstance.deletesong(cancion)
    DataBaseManager.sharedInstance.saveSongsDatBaseChanges(
        self.navigationController?.popViewControllerAnimated(true)
    })
    alert.addAction(action)
    alert.addAction(UIAlertAction(title: "No", style: .Cancel, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)

}

When I do not place the alert if I complete the action, but when I am alerting, the button does not work

    
asked by Lrawls 08.12.2016 в 21:36
source

1 answer

0

You probably have something badly defined on the line:

let action = UIAlertAction(title: "Si", style: .Default, handler: {(action) in
        let cancion: Cancion = DataBaseManager.sharedInstance.getSongByKey( "id", value: Int(self.lblid.text!)!)
    DataBaseManager.sharedInstance.deletesong(cancion)
    DataBaseManager.sharedInstance.saveSongsDatBaseChanges(
        self.navigationController?.popViewControllerAnimated(true)
    })

Since when executing everything else (With some upper case corrections for swift3)

    @IBAction func btnEliminar(_ sender: Any) {
    let alert = UIAlertController(title: "Eliminar", message: "Esta a punto de eliminar una cancion", preferredStyle: .alert)

    let action = UIAlertAction(title: "Si", style: .default, handler: {(action) in
        print("Elimina")
    })
    alert.addAction(action)

    alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
    self.present(alert, animated: true, completion: nil)
}

It works perfectly:

    
answered by 09.12.2016 / 15:41
source