{"id":582,"date":"2023-02-25T19:36:13","date_gmt":"2023-02-25T11:36:13","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=582"},"modified":"2023-04-29T20:31:36","modified_gmt":"2023-04-29T12:31:36","slug":"swift-ui-alert-box-uialertview","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/swift-ui-alert-box-uialertview\/","title":{"rendered":"Swift UI &#8211; \u544a\u8b66\u6846\uff08UIAlertView\uff09"},"content":{"rendered":"<blockquote>\n<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4<\/p>\n<\/blockquote>\n<h3>\u521b\u5efa\u544a\u8b66\u6846<\/h3>\n<p>\u521b\u5efa\u5e76\u5f39\u51fa\u4e00\u4e2a\u544a\u8b66\u6846\uff0c\u5e76\u5e26\u6709\u201c\u786e\u5b9a\u201d\u548c\u201c\u53d6\u6d88\u201d\u4e24\u4e2a\u6309\u94ae<\/p>\n<p><!-- more --><\/p>\n<blockquote>\n<p>\u6ce8\uff1a\u81eaiOS 8\u8d77\uff0c\u5efa\u8bae\u4f7f\u7528UIAlertController\u3002\u70b9\u51fb\u67e5\u770bUIAlertController\u7684\u7528\u6cd5<\/p>\n<\/blockquote>\n<pre><code class=\"language-swift\">class ViewController: UIViewController {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        let alertView = UIAlertView()\n        alertView.title = &quot;\u7cfb\u7edf\u63d0\u793a&quot;\n        alertView.message = &quot;\u60a8\u786e\u5b9a\u8981\u79bb\u5f00appblog.cn\u5417\uff1f&quot;\n        alertView.addButtonWithTitle(&quot;\u53d6\u6d88&quot;)\n        alertView.addButtonWithTitle(&quot;\u786e\u5b9a&quot;)\n        alertView.cancelButtonIndex = 0\n        alertView.delegate = self;\n        alertView.show()\n    }\n\n    func alertView(alertView:UIAlertView, clickedButtonAtIndex buttonIndex: Int) {\n        if (buttonIndex == alertView.cancelButtonIndex) {\n            print(&quot;\u70b9\u51fb\u4e86\u53d6\u6d88&quot;)\n        } else {\n            print(&quot;\u70b9\u51fb\u4e86\u786e\u8ba4&quot;)\n        }\n    }\n}<\/code><\/pre>\n<h3>\u544a\u8b66\u6846\u6837\u5f0f<\/h3>\n<p>\u544a\u8b66\u6846\u6709\u4e0b\u97624\u79cd\u6837\u5f0f<\/p>\n<pre><code class=\"language-swift\">Default\uff1a\u9ed8\u8ba4\u6837\u5f0f\nPlainTextInput\uff1a\u5e26\u8f93\u5165\u6846\u7684\u544a\u8b66\u6846\nSecureTextInput\uff1a\u5e26\u5bc6\u7801\u6846\u7684\u544a\u8b66\u6846\nLoginAndPasswordInput\uff1a\u5e26\u8f93\u5165\u6846\u548c\u5bc6\u7801\u6846\u7684\u544a\u8b66\u6846<\/code><\/pre>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528\u8f93\u5165\u6846\u548c\u5bc6\u7801\u6846\u7684\u544a\u8b66\u6846\u6837\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift\">import UIKit\n\nclass ViewController: UIViewController {\n\n    var alertView = UIAlertView()\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        alertView.title = &quot;\u7cfb\u7edf\u767b\u5f55&quot;\n        alertView.message = &quot;\u8bf7\u8f93\u5165\u7528\u6237\u540d\u548c\u5bc6\u7801\uff01&quot;\n        alertView.addButtonWithTitle(&quot;\u53d6\u6d88&quot;)\n        alertView.addButtonWithTitle(&quot;\u786e\u5b9a&quot;)\n        alertView.cancelButtonIndex = 0\n        alertView.delegate = self;\n        alertView.alertViewStyle = UIAlertViewStyle.LoginAndPasswordInput\n        alertView.show()\n    }\n\n    func alertView(alertView:UIAlertView, clickedButtonAtIndex buttonIndex: Int) {\n        if (buttonIndex == alertView.cancelButtonIndex) {\n            print(&quot;\u70b9\u51fb\u4e86\u53d6\u6d88&quot;)\n        } else {\n            let name = alertView.textFieldAtIndex(0)\n            let password = alertView.textFieldAtIndex(1)\n            print(&quot;\u7528\u6237\u540d\u662f\uff1a\\(name!.text) \u5bc6\u7801\u662f\uff1a\\(password!.text)&quot;)\n        }\n    }\n\n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4 \u521b\u5efa\u544a\u8b66\u6846 \u521b\u5efa\u5e76\u5f39\u51fa\u4e00\u4e2a\u544a\u8b66\u6846\uff0c\u5e76\u5e26\u6709\u201c\u786e\u5b9a\u201d\u548c\u201c\u53d6\u6d88\u201d\u4e24\u4e2a\u6309\u94ae \u6ce8\uff1a\u81eaiOS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[171],"tags":[],"class_list":["post-582","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=582"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/582\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}