I want to show an alert when I press a button that is in a tableviewcell and it gives me the following error:
'NSInvalidArgumentException', reason: 'Application tried to present modal view controller on itself. Presenting controller is.
This is my code:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CeldaID", for: indexPath) as! ComprarTableViewCell
cell.nombreEntradaLBL.text = nombreConcierto[indexPath.row]
cell.comprarEntradaIMG.image = UIImage(named: imagenes[indexPath.row])
cell.fechaEntradasLBL.text = fechas[indexPath.row]
cell.comprarBTN.addTarget(self, action: #selector(ComprarTableViewController.mostrarAlerta), for: .touchUpInside)
return cell
}
@objc func mostrarAlerta(){
let alerta = UIAlertController(title: "Compra satisfactoria", message: "Se han comprado su entrada/as", preferredStyle: .alert)
alerta.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
alerta.present(alerta,animated: true)
}