未分類

アラートを表示する

投稿日:

アラートを表示するメソッド

//アラート
    func displayAleart() {
        let alert: UIAlertController = UIAlertController(title: "アラート表示", message: "保存してもいいですか?", preferredStyle:  UIAlertController.Style.alert)

        let defaultAction: UIAlertAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:{
            (action: UIAlertAction!) -> Void in
            print("OK")
        })
        let cancelAction: UIAlertAction = UIAlertAction(title: "キャンセル", style: UIAlertAction.Style.cancel, handler:{
            (action: UIAlertAction!) -> Void in
            print("Cancel")
        })

        alert.addAction(cancelAction)
        alert.addAction(defaultAction)

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

参考:【Swift】アラートを表示する(Alert/ActionSheet)

-未分類

執筆者:

関連記事

no image

CGColorをRGBで指定する方法

uiViewの色指定はUIColorでなく、CGColorになってる。 CGColorをUIColorと同じやり方でRGB指定するとエラーが出る。 一度定数化してから、入れたら解決した。 let cu …

no image

モーダルからdissmissで戻った時に処理を行う方法

遷移先がModalの場合、遷移先から戻った時に呼ばれるメソッドviewWillApperが使えない。 遷移先を.fullscreenに変更することでviewWillApperが使えるようになるが、ここ …

no image

プロトコルの仕様書を見るコツ

プロトコルのデリゲートメソッドを確認したい。 プロトコル名をcommand+クリックJump to Definitionで設計図が見られる。 protocol UITableViewDelegateの …

no image

文字列の先頭から何文字を取り出す

文字列の先頭から、または後ろから、任意の数の文字を取り出す方法。 let text = “こんにちは、世界” //先頭から5文字を取り出す let first = String(text.prefix …

no image

実機テストでエラーが出る時の対処法

エラー:Could not locate device support files が出る時 iPhoneのバージョンが今のxcodeのバージョンに対応していないことを示す。 iOSをアップデートする …