技術と本について書くブログ

技術と本について書くblog。技術メモなど雑記を書いているblog。

UIViewControllerでViewControllerを閉じる方法

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)

stackoverflow.com