<small id='Dnwg6'></small><noframes id='Dnwg6'>

    • <bdo id='Dnwg6'></bdo><ul id='Dnwg6'></ul>
    <legend id='Dnwg6'><style id='Dnwg6'><dir id='Dnwg6'><q id='Dnwg6'></q></dir></style></legend>
    <tfoot id='Dnwg6'></tfoot>

      <i id='Dnwg6'><tr id='Dnwg6'><dt id='Dnwg6'><q id='Dnwg6'><span id='Dnwg6'><b id='Dnwg6'><form id='Dnwg6'><ins id='Dnwg6'></ins><ul id='Dnwg6'></ul><sub id='Dnwg6'></sub></form><legend id='Dnwg6'></legend><bdo id='Dnwg6'><pre id='Dnwg6'><center id='Dnwg6'></center></pre></bdo></b><th id='Dnwg6'></th></span></q></dt></tr></i><div id='Dnwg6'><tfoot id='Dnwg6'></tfoot><dl id='Dnwg6'><fieldset id='Dnwg6'></fieldset></dl></div>

      1. 哪里可以找到关于 swift alert (UIAlertController) 的清

        时间:2023-08-28
        <tfoot id='L6hWD'></tfoot>

        <small id='L6hWD'></small><noframes id='L6hWD'>

        1. <legend id='L6hWD'><style id='L6hWD'><dir id='L6hWD'><q id='L6hWD'></q></dir></style></legend>

        2. <i id='L6hWD'><tr id='L6hWD'><dt id='L6hWD'><q id='L6hWD'><span id='L6hWD'><b id='L6hWD'><form id='L6hWD'><ins id='L6hWD'></ins><ul id='L6hWD'></ul><sub id='L6hWD'></sub></form><legend id='L6hWD'></legend><bdo id='L6hWD'><pre id='L6hWD'><center id='L6hWD'></center></pre></bdo></b><th id='L6hWD'></th></span></q></dt></tr></i><div id='L6hWD'><tfoot id='L6hWD'></tfoot><dl id='L6hWD'><fieldset id='L6hWD'></fieldset></dl></div>

                <tbody id='L6hWD'></tbody>

                <bdo id='L6hWD'></bdo><ul id='L6hWD'></ul>
                  本文介绍了哪里可以找到关于 swift alert (UIAlertController) 的清晰解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  对此找不到清晰而翔实的解释.

                  Couldn't find a clear and informative explanation for this.

                  推荐答案

                  在一个主题上搜索了一段时间后我没有找到一个清晰的解释,即使在它的类参考中UIAlertController 参考

                  After searching a while on a subject I didn't find a clear explanation , even in it's class reference UIAlertController Reference

                  没关系,但对我来说不够清楚.

                  It is ok, but not clear enough for me.

                  所以在收集了一些和平之后,我决定做出自己的解释(希望对你有帮助)

                  So after collecting some peaces I decided to make my own explanation (Hope it helps)

                  就这样吧:

                  1. UIAlertView 如所指出的那样被弃用:Swift 中的 UIAlertView
                  2. UIAlertController 应该在 iOS8+ 中使用所以要先创建一个,我们需要实例化它,Constructor(init) 获取 3 个参数:
                  1. UIAlertView is deprecated as pointed out : UIAlertView in Swift
                  2. UIAlertController should be used in iOS8+ so to create one first we need to instantiate it, the Constructor(init) gets 3 parameters:

                  2.1 title:String -> 显示在警报对话框顶部的大粗体文本

                  2.1 title:String -> big-bold text to display on the top of alert's dialog box

                  2.2 message:String -> 较小的文本(几乎可以解释它的自身)

                  2.2 message:String -> smaller text (pretty much explains it's self)

                  2.3 prefferedStyle:UIAlertControllerStyle -> 定义对话框样式,大多数情况下:UIAlertControllerStyle.Alert

                  2.3 prefferedStyle:UIAlertControllerStyle -> define the dialog box style, in most cases: UIAlertControllerStyle.Alert

                  1. 现在要实际向用户展示它,我们可以使用 showViewControllerpresentViewController 并将我们的警报作为参数传递

                  1. Now to actually show it to the user, we can use showViewController or presentViewController and pass our alert as parameter

                  要添加一些与用户的交互,我们可以使用:

                  To add some interaction with a user we can use:

                  4.1UIAlertController.addAction 创建按钮

                  4.2UIAlertController.addTextField 创建文本字段

                  编辑说明:以下代码示例,已针对 swift 3 语法进行了更新

                  Edit note: code examples below, updated for swift 3 syntax

                  示例 1:简单对话框

                  @IBAction func alert1(sender: UIButton) {
                       //simple alert dialog
                      let alert=UIAlertController(title: "Alert 1", message: "One has won", preferredStyle: UIAlertControllerStyle.alert);
                      //show it
                      show(alert, sender: self);
                  }
                  

                  示例 2:带有一个输入 textField 的对话框 &两个按钮

                  Example 2: Dialog with one input textField & two buttons

                  @IBAction func alert2(sender: UIButton) {
                      //Dialog with one input textField & two buttons
                      let alert=UIAlertController(title: "Alert 2", message: "Two will win too", preferredStyle: UIAlertControllerStyle.alert);
                      //default input textField (no configuration...)
                      alert.addTextField(configurationHandler: nil);
                      //no event handler (just close dialog box)
                      alert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.cancel, handler: nil));
                      //event handler with closure
                      alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.default, handler: {(action:UIAlertAction) in
                          let fields = alert.textFields!;
                          print("Yes we can: "+fields[0].text!);
                      }));
                      present(alert, animated: true, completion: nil);
                  }
                  

                  示例 3:一个自定义输入 textField &一键

                  Example 3: One customized input textField & one button

                  @IBAction func alert3(sender: UIButton) {
                     // one input & one button
                     let alert=UIAlertController(title: "Alert 3", message: "Three will set me free", preferredStyle: UIAlertControllerStyle.alert);
                  
                      //configured input textField
                      var field:UITextField?;// operator ? because it's been initialized later
                      alert.addTextField(configurationHandler:{(input:UITextField)in
                          input.placeholder="I am displayed, when there is no value ;-)";
                          input.clearButtonMode=UITextFieldViewMode.whileEditing;
                          field=input;//assign to outside variable(for later reference)
                      });
                      //alert3 yesHandler -> defined in the same scope with alert, and passed as event handler later
                      func yesHandler(actionTarget: UIAlertAction){
                          print("YES -> !!");
                          //print text from 'field' which refer to relevant input now
                          print(field!.text!);//operator ! because it's Optional here
                      }
                      //event handler with predefined function
                      alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.default, handler: yesHandler));
                  
                      present(alert, animated: true, completion: nil);
                   }
                  

                  希望有帮助,祝你好运 ;-)

                  这篇关于哪里可以找到关于 swift alert (UIAlertController) 的清晰解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何实现材料指南中描述的全屏对话框? 下一篇:在活动之上创建一个透明对话框

                  相关文章

                  最新文章

                    <legend id='prTKw'><style id='prTKw'><dir id='prTKw'><q id='prTKw'></q></dir></style></legend>

                    <small id='prTKw'></small><noframes id='prTKw'>

                    <i id='prTKw'><tr id='prTKw'><dt id='prTKw'><q id='prTKw'><span id='prTKw'><b id='prTKw'><form id='prTKw'><ins id='prTKw'></ins><ul id='prTKw'></ul><sub id='prTKw'></sub></form><legend id='prTKw'></legend><bdo id='prTKw'><pre id='prTKw'><center id='prTKw'></center></pre></bdo></b><th id='prTKw'></th></span></q></dt></tr></i><div id='prTKw'><tfoot id='prTKw'></tfoot><dl id='prTKw'><fieldset id='prTKw'></fieldset></dl></div>

                    <tfoot id='prTKw'></tfoot>
                        <bdo id='prTKw'></bdo><ul id='prTKw'></ul>