[Swift] 경고 표시(Alert/AtionSheet)
개발 환경
개요 
버튼을 눌렀을 때 표시되는 경고 대화 상자의 기본 쓰기 방법을 설명합니다.
득점 
경고 표시 
비주얼 스타일: Alert
 
대화 상자에 바람 경보 표시
Display
 
 
Swift Code
 
AlertController.swift// ボタンを押下した時にアラートを表示するメソッド
@IBAction func dispAlert(sender: UIButton) {
    // ① UIAlertControllerクラスのインスタンスを生成
    // タイトル, メッセージ, Alertのスタイルを指定する
    // 第3引数のpreferredStyleでアラートの表示スタイルを指定する
    let alert: UIAlertController = UIAlertController(title: "アラート表示", message: "保存してもいいですか?", preferredStyle:  UIAlertControllerStyle.Alert)
    // ② Actionの設定
    // Action初期化時にタイトル, スタイル, 押された時に実行されるハンドラを指定する
    // 第3引数のUIAlertActionStyleでボタンのスタイルを指定する
    // OKボタン
    let defaultAction: UIAlertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{
        // ボタンが押された時の処理を書く(クロージャ実装)
        (action: UIAlertAction!) -> Void in
        print("OK")
    })
    // キャンセルボタン
    let cancelAction: UIAlertAction = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.Cancel, handler:{
        // ボタンが押された時の処理を書く(クロージャ実装)
        (action: UIAlertAction!) -> Void in
        print("Cancel")
    })
    // ③ UIAlertControllerにActionを追加
    alert.addAction(cancelAction)
    alert.addAction(defaultAction)
    // ④ Alertを表示
    presentViewController(alert, animated: true, completion: nil)
}
비주얼 스타일: ActionSheet
 
화면 아래에서 나오는 경보를 표시합니다.
Display
 
 
Swift Code
 
UIAlert Controller 클래스의 인스턴스가 생성될 때 세 번째 매개변수의 preferredStyle에서 ActionSheet를 지정합니다.(기타 코드는 표시 스타일: Alert와 동일)
AlertController.swiftlet alert: UIAlertController = UIAlertController(title: "アラート表示", message: "保存してもいいですか?", preferredStyle:  UIAlertControllerStyle.ActionSheet)
버튼 스타일 정보
 
다음 3가지 유형을 지정할 수 있습니다.
UIAlertActionStyle
설명
default
문자: 표준/다중 지정 가능
cancel
텍스트: 굵게/여러 개/위치를 지정할 수 없으며 맨 아래에 고정합니다.
destructive
문자: 빨간색/여러 개 지정 가능
디스플레이 스타일
 
 
표시 스타일: ActionSheet
 
 
Swift Code
 // Defaultボタン
let defaultAction_1: UIAlertAction = UIAlertAction(title: "default_1", style: UIAlertActionStyle.Default, handler:{
    (action: UIAlertAction!) -> Void in
    print("defaultAction_1")
})
let defaultAction_2: UIAlertAction = UIAlertAction(title: "default_2", style: UIAlertActionStyle.Default, handler:{
    (action: UIAlertAction!) -> Void in
    print("defaultAction_2")
})
// Cancelボタン
let cancelAction: UIAlertAction = UIAlertAction(title: "cancel", style: UIAlertActionStyle.Cancel, handler:{
    (action: UIAlertAction!) -> Void in
    print("cancelAction")
})
// Destructiveボタン
let destructiveAction_1: UIAlertAction = UIAlertAction(title: "destructive_1", style: UIAlertActionStyle.Destructive, handler:{
    (action: UIAlertAction!) -> Void in
    print("destructiveAction_1")
})
let destructiveAction_2: UIAlertAction = UIAlertAction(title: "destructive_2", style: UIAlertActionStyle.Destructive, handler:{
    (action: UIAlertAction!) -> Void in
    print("destructiveAction_2")
})
닫힌 상태에서 버튼 동작 처리
 
Swift Code
 
AlertController.swiftlet defaultAction: UIAlertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{
    // ボタンが押された時の処理を書く(クロージャ実装)
    (action: UIAlertAction!) -> Void in
    print("OK")
})
이번에는 간단하게 버튼을 누르면 "OK"문자열을 콘솔에 출력합니다.
또 다른 기회에 폐쇄에 대해 쓰고 싶은데 최소한만 건드리면 폐쇄라는 말은 한마디로'이름 없는 함수식'이다. 기본적인 작법은 다음과 같다.{(引数: 引数の型) -> (戻り値の型) in
    // 処理
}
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여([Swift] 경고 표시(Alert/AtionSheet)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/funacchi/items/b76e62eb82fc8d788da5
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
// ボタンを押下した時にアラートを表示するメソッド
@IBAction func dispAlert(sender: UIButton) {
    // ① UIAlertControllerクラスのインスタンスを生成
    // タイトル, メッセージ, Alertのスタイルを指定する
    // 第3引数のpreferredStyleでアラートの表示スタイルを指定する
    let alert: UIAlertController = UIAlertController(title: "アラート表示", message: "保存してもいいですか?", preferredStyle:  UIAlertControllerStyle.Alert)
    // ② Actionの設定
    // Action初期化時にタイトル, スタイル, 押された時に実行されるハンドラを指定する
    // 第3引数のUIAlertActionStyleでボタンのスタイルを指定する
    // OKボタン
    let defaultAction: UIAlertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{
        // ボタンが押された時の処理を書く(クロージャ実装)
        (action: UIAlertAction!) -> Void in
        print("OK")
    })
    // キャンセルボタン
    let cancelAction: UIAlertAction = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.Cancel, handler:{
        // ボタンが押された時の処理を書く(クロージャ実装)
        (action: UIAlertAction!) -> Void in
        print("Cancel")
    })
    // ③ UIAlertControllerにActionを追加
    alert.addAction(cancelAction)
    alert.addAction(defaultAction)
    // ④ Alertを表示
    presentViewController(alert, animated: true, completion: nil)
}
let alert: UIAlertController = UIAlertController(title: "アラート表示", message: "保存してもいいですか?", preferredStyle:  UIAlertControllerStyle.ActionSheet)
// Defaultボタン
let defaultAction_1: UIAlertAction = UIAlertAction(title: "default_1", style: UIAlertActionStyle.Default, handler:{
    (action: UIAlertAction!) -> Void in
    print("defaultAction_1")
})
let defaultAction_2: UIAlertAction = UIAlertAction(title: "default_2", style: UIAlertActionStyle.Default, handler:{
    (action: UIAlertAction!) -> Void in
    print("defaultAction_2")
})
// Cancelボタン
let cancelAction: UIAlertAction = UIAlertAction(title: "cancel", style: UIAlertActionStyle.Cancel, handler:{
    (action: UIAlertAction!) -> Void in
    print("cancelAction")
})
// Destructiveボタン
let destructiveAction_1: UIAlertAction = UIAlertAction(title: "destructive_1", style: UIAlertActionStyle.Destructive, handler:{
    (action: UIAlertAction!) -> Void in
    print("destructiveAction_1")
})
let destructiveAction_2: UIAlertAction = UIAlertAction(title: "destructive_2", style: UIAlertActionStyle.Destructive, handler:{
    (action: UIAlertAction!) -> Void in
    print("destructiveAction_2")
})
let defaultAction: UIAlertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{
    // ボタンが押された時の処理を書く(クロージャ実装)
    (action: UIAlertAction!) -> Void in
    print("OK")
})
{(引数: 引数の型) -> (戻り値の型) in
    // 処理
}
Reference
이 문제에 관하여([Swift] 경고 표시(Alert/AtionSheet)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/funacchi/items/b76e62eb82fc8d788da5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)