dismissの代わりに
self.navigationController?.popViewController(animated: true)
を使う
let alert = UIAlertController( title: "ViewControllerを閉じる",message: "hoge", preferredStyle: UIAlertController.Style.alert) alert.addTextField( configurationHandler: { ( create: UITextField!) -> Void in create.placeholder = "Category?"}) let defaultAction : UIAlertAction = UIAlertAction(title: "OK",style: UIAlertAction.Style.default,handler: {(action: UIAlertAction!) -> Void in self.navigationController?.popViewController(animated: true) }) let cancelAction :UIAlertAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel, handler: {(action: UIAlertAction!) -> Void in}) alert.addAction(cancelAction) alert.addAction(defaultAction) self.present(alert, animated: true, completion: nil)