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

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

      1. <i id='v4JAn'><tr id='v4JAn'><dt id='v4JAn'><q id='v4JAn'><span id='v4JAn'><b id='v4JAn'><form id='v4JAn'><ins id='v4JAn'></ins><ul id='v4JAn'></ul><sub id='v4JAn'></sub></form><legend id='v4JAn'></legend><bdo id='v4JAn'><pre id='v4JAn'><center id='v4JAn'></center></pre></bdo></b><th id='v4JAn'></th></span></q></dt></tr></i><div id='v4JAn'><tfoot id='v4JAn'></tfoot><dl id='v4JAn'><fieldset id='v4JAn'></fieldset></dl></div>
        <tfoot id='v4JAn'></tfoot>
      2. 带有 OK 和 Cancel 的 Swift 警报视图:点击了哪个按钮

        时间:2023-08-28

          <tfoot id='6CFFZ'></tfoot>
            • <bdo id='6CFFZ'></bdo><ul id='6CFFZ'></ul>

              <small id='6CFFZ'></small><noframes id='6CFFZ'>

                <tbody id='6CFFZ'></tbody>
              • <legend id='6CFFZ'><style id='6CFFZ'><dir id='6CFFZ'><q id='6CFFZ'></q></dir></style></legend>

                <i id='6CFFZ'><tr id='6CFFZ'><dt id='6CFFZ'><q id='6CFFZ'><span id='6CFFZ'><b id='6CFFZ'><form id='6CFFZ'><ins id='6CFFZ'></ins><ul id='6CFFZ'></ul><sub id='6CFFZ'></sub></form><legend id='6CFFZ'></legend><bdo id='6CFFZ'><pre id='6CFFZ'><center id='6CFFZ'></center></pre></bdo></b><th id='6CFFZ'></th></span></q></dt></tr></i><div id='6CFFZ'><tfoot id='6CFFZ'></tfoot><dl id='6CFFZ'><fieldset id='6CFFZ'></fieldset></dl></div>
                1. 本文介绍了带有 OK 和 Cancel 的 Swift 警报视图:点击了哪个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在 Xcode 中有一个用 Swift 编写的警报视图,我想确定用户选择了哪个按钮(它是一个确认对话框)什么都不做或执行什么.

                  I have an alert view in Xcode written in Swift and I'd like to determine which button the user selected (it is a confirmation dialog) to do nothing or to execute something.

                  目前我有:

                  @IBAction func pushedRefresh(sender: AnyObject) {
                      var refreshAlert = UIAlertView()
                      refreshAlert.title = "Refresh?"
                      refreshAlert.message = "All data will be lost."
                      refreshAlert.addButtonWithTitle("Cancel")
                      refreshAlert.addButtonWithTitle("OK")
                      refreshAlert.show()
                  }
                  

                  我可能用错了按钮,请纠正我,因为这对我来说是全新的.

                  I'm probably using the buttons wrong, please do correct me since this is all new for me.

                  推荐答案

                  如果你使用的是 iOS8,你应该使用 UIAlertController — UIAlertView 是 已弃用.

                  If you are using iOS8, you should be using UIAlertController — UIAlertView is deprecated.

                  这是一个如何使用它的示例:

                  Here is an example of how to use it:

                  var refreshAlert = UIAlertController(title: "Refresh", message: "All data will be lost.", preferredStyle: UIAlertControllerStyle.Alert)
                  
                  refreshAlert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action: UIAlertAction!) in
                    print("Handle Ok logic here")
                    }))
                  
                  refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action: UIAlertAction!) in
                    print("Handle Cancel Logic here")
                    }))
                  
                  presentViewController(refreshAlert, animated: true, completion: nil)
                  

                  您可以看到 UIAlertAction 的块处理程序处理按钮按下.一个很棒的教程在这里(尽管本教程不是使用 swift 编写的):http://hayageek.com/uialertcontroller-example-ios/

                  As you can see the block handlers for the UIAlertAction handle the button presses. A great tutorial is here (although this tutorial is not written using swift): http://hayageek.com/uialertcontroller-example-ios/

                  Swift 3 更新:

                  let refreshAlert = UIAlertController(title: "Refresh", message: "All data will be lost.", preferredStyle: UIAlertControllerStyle.alert)
                  
                  refreshAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in
                      print("Handle Ok logic here")
                  }))
                  
                  refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
                      print("Handle Cancel Logic here")
                  }))
                  
                  present(refreshAlert, animated: true, completion: nil)
                  

                  Swift 5 更新:

                  let refreshAlert = UIAlertController(title: "Refresh", message: "All data will be lost.", preferredStyle: UIAlertControllerStyle.alert)
                  
                  refreshAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in
                        print("Handle Ok logic here")
                  }))
                  
                  refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
                        print("Handle Cancel Logic here")
                  }))
                  
                  present(refreshAlert, animated: true, completion: nil)
                  

                  Swift 5.3 更新:

                  let refreshAlert = UIAlertController(title: "Refresh", message: "All data will be lost.", preferredStyle: UIAlertController.Style.alert)
                  
                  refreshAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in
                        print("Handle Ok logic here")
                  }))
                  
                  refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
                        print("Handle Cancel Logic here")
                  }))
                  
                  present(refreshAlert, animated: true, completion: nil)
                  

                  这篇关于带有 OK 和 Cancel 的 Swift 警报视图:点击了哪个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何通过点击动画 UIImageview 以显示全屏? 下一篇:Android 后退按钮和进度对话框

                  相关文章

                  最新文章

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

                3. <tfoot id='i9cYP'></tfoot>

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

                    • <bdo id='i9cYP'></bdo><ul id='i9cYP'></ul>