公開日:
UITableViewのCell削除時にアラート表示が必要になり調べながら実装しました!備忘録として記録しておきます。
削除ボタンボタンの場合のコードです
可能な限り簡潔に記述しています。
@IBAction func deleteButton(_ sender: Any) { //アラートを表示する↓=================== let alert: UIAlertController = UIAlertController(title: "注意", message: "削除してもいいですか?", preferredStyle: .actionSheet) let canselAction: UIAlertAction = UIAlertAction(title: "キャンセル", style: .cancel) { (UIAlertAction) in print("キャンセル") } let okAction: UIAlertAction = UIAlertAction(title: "削除", style: .destructive) { (UIAlertAction) in // 「削除」が押された時の処理をここに記述 } //アラートに設定を反映させる alert.addAction(okAction) alert.addAction(canselAction) //アラート画面を表示させる present(alert, animated: true, completion: nil) //アラートを表示する↑=================== }