Skip to content

Instantly share code, notes, and snippets.

@NoasProject
Created June 19, 2015 12:40
Show Gist options
  • Select an option

  • Save NoasProject/d4b82812c508685f51d2 to your computer and use it in GitHub Desktop.

Select an option

Save NoasProject/d4b82812c508685f51d2 to your computer and use it in GitHub Desktop.

Revisions

  1. NoasProject created this gist Jun 19, 2015.
    51 changes: 51 additions & 0 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@

    import UIKit

    class ViewController: UIViewController {

    override func viewDidLoad() {
    super.viewDidLoad()

    let alert:UIAlertController = UIAlertController(title:"Swiftアラートテスト2",
    message: "アラートのテストです。",
    preferredStyle: UIAlertControllerStyle.Alert)
    presentViewController(alert, animated: true, completion: nil)

    let cancelAction:UIAlertAction = UIAlertAction(title: "Cancel",
    style: UIAlertActionStyle.Cancel,
    handler:{
    (action:UIAlertAction!) -> Void in
    /*
    キャンセルボタンを押された際の動作
    */
    println("キャンセルボタンで一番下に表示されます")
    })

    let defaultAction:UIAlertAction = UIAlertAction(title: "通常ボタン",
    style: UIAlertActionStyle.Default,
    handler:{
    (action:UIAlertAction!) -> Void in
    /*
    通常ボタンが押された際のAction
    */
    println("一般的なボタン")
    })

    let destructiveAction:UIAlertAction = UIAlertAction(title: "削除ボタン",
    style: UIAlertActionStyle.Destructive,
    handler:{
    (action:UIAlertAction!) -> Void in
    /*
    削除ボタンが押された際のAction
    */
    println("削除や変動的な処理の場合に利用します")
    })


    alert.addAction(cancelAction) //キャンセルボタンの生成
    alert.addAction(defaultAction) //デェフォルトの通常ボタンの生成
    alert.addAction(destructiveAction) //削除など変異的なボタンの生成

    self.navigationController?.pushViewController(alert, animated: true)
    }
    }