Skip to content

Instantly share code, notes, and snippets.

@tdtsh
Last active January 17, 2016 02:34
Show Gist options
  • Save tdtsh/4abab4fcf5dc3e9d8b18 to your computer and use it in GitHub Desktop.
Save tdtsh/4abab4fcf5dc3e9d8b18 to your computer and use it in GitHub Desktop.
Swift2 で Alert を表示
class MasterViewController: UITableViewController {
...
override func viewDidLoad() {
...
let cameraButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Camera, target: self, action: "doCamera:")
...
}
...
func doCamera(sender: UIButton) {
// UIAlertControllerを作成する.
let sampleAlert: UIAlertController = UIAlertController(title: "アラートです", message: "カメラボタン押しました", preferredStyle: .Alert)
// アクションを作成、追加
let yesAction = UIAlertAction(title: "OK", style: .Default) { action in print("OK!!") }
sampleAlert.addAction(yesAction)
// UIAlertを表示
self.presentViewController(sampleAlert, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment