Skip to content

Instantly share code, notes, and snippets.

@ochim
Last active June 19, 2020 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochim/363ca39c682e2a7e8a245540babe8c35 to your computer and use it in GitHub Desktop.
Save ochim/363ca39c682e2a7e8a245540babe8c35 to your computer and use it in GitHub Desktop.
[ios]簡易なアラートダイアログを表示する
extension UIViewController {
    // 簡易なアラートダイアログを表示する
    func showSimpleAlert(title: String?, message: String?, action: ((UIAlertAction) -> Void)? = nil) {
        let alertController = UIAlertController(title: title,
                                                message: message,
                                                preferredStyle: .alert)
        let defaultAction = UIAlertAction(title: "OK",
                                          style: .default,
                                          handler: action)
        alertController.addAction(defaultAction)

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

// 使い方例
self.showSimpleAlert(title: "hogehoge", message: "hello")

self.showSimpleAlert(title: nil, message: "hello", action: { _ in
    self.navigationController?.popViewController(animated: true)
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment