{"id":583,"date":"2023-02-25T19:37:06","date_gmt":"2023-02-25T11:37:06","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=583"},"modified":"2023-04-29T20:31:28","modified_gmt":"2023-04-29T12:31:28","slug":"swift-ui-action-sheet-uiactionsheet","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/swift-ui-action-sheet-uiactionsheet\/","title":{"rendered":"Swift UI &#8211; \u64cd\u4f5c\u8868\uff08UIActionSheet\uff09"},"content":{"rendered":"<blockquote>\n<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4<\/p>\n<\/blockquote>\n<h3>\u521b\u5efa\u64cd\u4f5c\u8868<\/h3>\n<p>\u521b\u5efa\u4e00\u4e2a\u64cd\u4f5c\u8868\uff08\u6216\u53eb\u5e95\u90e8\u8b66\u544a\u6846\uff09\u5e76\u5f39\u51fa\u663e\u793a<\/p>\n<p><!-- more --><\/p>\n<blockquote>\n<p>\u6ce8\uff1a\u81eaiOS 8\u8d77\uff0c\u5efa\u8bae\u4f7f\u7528UIAlertController\u4ee3\u66ffUIActionSheet\u3002\u70b9\u51fb\u67e5\u770bUIAlertController\u7684\u7528\u6cd5<\/p>\n<\/blockquote>\n<pre><code class=\"language-swift\">import UIKit\n\nclass ViewController: UIViewController,UIActionSheetDelegate {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        let actionSheet=UIActionSheet()\n        \/\/actionSheet.title = &quot;\u8bf7\u9009\u62e9\u64cd\u4f5c&quot;\n        actionSheet.addButtonWithTitle(&quot;\u53d6\u6d88&quot;)\n        actionSheet.addButtonWithTitle(&quot;\u52a8\u4f5c1&quot;)\n        actionSheet.addButtonWithTitle(&quot;\u52a8\u4f5c2&quot;)\n        actionSheet.cancelButtonIndex = 0\n        actionSheet.delegate = self\n        actionSheet.showInView(self.view);\n    }\n\n    func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {\n        print(&quot;\u70b9\u51fb\u4e86\uff1a&quot; + actionSheet.buttonTitleAtIndex(buttonIndex)!)\n    }\n}<\/code><\/pre>\n<h3>\u663e\u793a\u65b9\u5f0f<\/h3>\n<p>\u5728\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u5de5\u5177\u6761\uff0c\u6216\u6807\u7b7e\u6761\u4e2d\u663e\u793a\u7684\u8c03\u7528\u65b9\u5f0f\u662f\u4e0d\u4e00\u6837\u7684<\/p>\n<pre><code class=\"language-swift\">actionSheet.showInView(self.view);  \/\/\u4e00\u822c\u60c5\u51b5\nactionSheet.showFromToolbar(self.navigationController.toolbar)  \/\/\u5de5\u5177\u6761\u7684\u60c5\u51b5\u4e0b\nactionSheet.showFromTabBar(self.tabBar)  \/\/\u6807\u7b7e\u6761\u7684\u60c5\u51b5\u4e0b<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4 \u521b\u5efa\u64cd\u4f5c\u8868 \u521b\u5efa\u4e00\u4e2a\u64cd\u4f5c\u8868\uff08\u6216\u53eb\u5e95\u90e8\u8b66\u544a\u6846\uff09\u5e76\u5f39\u51fa\u663e\u793a \u6ce8\uff1a\u81eaiOS 8\u8d77\uff0c\u5efa\u8bae [&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-583","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/583","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=583"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}