Получение ошибки SIGABRT при удалении строки tableView с помощью UIAlert - PullRequest
0 голосов
/ 25 июня 2018

Я пытаюсь удалить строку в моем tableView с помощью функции commit editstyle.Когда пользователь удаляет строку, я хочу, чтобы отображался UIAlertController.Я пробовал без предупреждения, это работает.Вот моя функция editStyle для коммита:

 func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
            if editingStyle == .delete {
                let sheet = UIAlertController(title: "Diesen Verein löschen?", message: "Wollen Sie diesen Verein für immer löschen?", preferredStyle:.alert)
                present(sheet, animated: true, completion: nil)
                let action1 = UIAlertAction(title: "Löschen", style: .default , handler: { (action) in
                    self.deleteClub(at: indexPath)
                })
                let action2 = UIAlertAction(title: "Abbrechen", style: .default, handler: { (action) in
                    self.dismiss(animated: true, completion: nil)
                })
                sheet.addAction(action1)
                sheet.addAction(action2)

                present(sheet, animated: true, completion: nil)
            }
        }

Вот моя функция удаления, но я не думаю, что здесь ошибка, потому что она работает без Alert.

func deleteClub(at indexPath: IndexPath){
            let club = clubs[indexPath.row]

            guard let managedContext = club.managedObjectContext else {
                return
            }
            managedContext.delete(club)

            do {
                try managedContext.save()

                clubs.remove(at: indexPath.row)

                tableViewClub.deleteRows(at: [indexPath], with: .automatic)
            } catch {
                print("Could not delete")

                tableViewClub.reloadRows(at: [indexPath], with: .automatic)
            }
        }
...