{"id":7000,"date":"2025-05-29T13:44:51","date_gmt":"2025-06-05T05:49:50","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7000"},"modified":"2025-06-05T13:44:51","modified_gmt":"2025-06-05T05:49:50","slug":"https-badgameshow-com-steven-176","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-176\/","title":{"rendered":"Swift UIAlertController \u8207 ActionSheet \u6559\u5b78\uff1a2025 \u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"swift, UIAlertController, ActionSheet, Swift 2025, iOS \u958b\u767c, \u7a0b\u5f0f\u6559\u5b78\"><\/p>\n<p>Swift \u662f\u4e00\u7a2e\u7c21\u55ae\u6613\u5b78\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u51fa\u529f\u80fd\u5f37\u5927\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u5728 Swift \u4e2d\uff0c<strong>UIAlertController<\/strong> \u548c <strong>ActionSheet<\/strong> \u662f\u5169\u7a2e\u5e38\u898b\u7684\u9078\u64c7\u65b9\u5f0f\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u5728\u61c9\u7528\u7a0b\u5f0f\u4e2d\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f UIAlertController\uff1f<\/h2>\n<p>UIAlertController \u662f\u4e00\u7a2e\u63d0\u4f9b\u4f7f\u7528\u8005\u591a\u7a2e\u9078\u64c7\u7684\u65b9\u5f0f\uff0c\u8b93\u4f7f\u7528\u8005\u80fd\u5920\u5728\u61c9\u7528\u7a0b\u5f0f\u4e2d\u9078\u64c7\u4e0d\u540c\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\uff1a\u53d6\u6d88\u3001\u78ba\u5b9a\u3001\u91cd\u8a66\u7b49\u7b49\u3002\u5b83\u7684\u4f7f\u7528\u65b9\u5f0f\u975e\u5e38\u7c21\u55ae\uff0c\u4ee5\u4e0b\u662f\u4f7f\u7528 <strong>UIAlertController<\/strong> \u7684\u7bc4\u4f8b\uff1a<\/p>\n<h2>\u4f7f\u7528 UIAlertController \u7684\u7a0b\u5f0f\u7bc4\u4f8b<\/h2>\n<pre><code class=\"language-swift line-numbers\">let alertController = UIAlertController(title: \"\u8b66\u544a\", message: \"\u9019\u662f\u4e00\u500b\u8b66\u544a\u8a0a\u606f\uff01\", preferredStyle: .alert)\n\nlet cancelAction = UIAlertAction(title: \"\u53d6\u6d88\", style: .cancel, handler: nil)\nlet okAction = UIAlertAction(title: \"\u78ba\u5b9a\", style: .default) { action in\n    print(\"\u4f7f\u7528\u8005\u9078\u64c7\u4e86\u78ba\u5b9a\")\n}\n\nalertController.addAction(cancelAction)\nalertController.addAction(okAction)\n\npresent(alertController, animated: true, completion: nil)\n<\/code><\/pre>\n<h2>\u4ec0\u9ebc\u662f ActionSheet\uff1f<\/h2>\n<p>ActionSheet \u662f\u53e6\u4e00\u7a2e\u63d0\u4f9b\u4f7f\u7528\u8005\u9078\u64c7\u7684\u65b9\u5f0f\uff0c\u901a\u5e38\u7528\u65bc\u9078\u64c7\u4e00\u9805\u64cd\u4f5c\u6216\u9078\u9805\u3002ActionSheet \u6703\u5f9e\u5c4f\u5e55\u5e95\u90e8\u5f48\u51fa\uff0c\u9069\u5408\u7528\u65bc\u9700\u8981\u4f7f\u7528\u8005\u7acb\u5373\u505a\u51fa\u9078\u64c7\u7684\u60c5\u666f\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 <strong>ActionSheet<\/strong> \u7684\u7bc4\u4f8b\uff1a<\/p>\n<h2>\u4f7f\u7528 ActionSheet \u7684\u7a0b\u5f0f\u7bc4\u4f8b<\/h2>\n<pre><code class=\"language-swift line-numbers\">let actionSheet = UIAlertController(title: \"\u9078\u64c7\u60a8\u7684\u9078\u9805\", message: \"\u8acb\u9078\u64c7\u4e00\u500b\u64cd\u4f5c\", preferredStyle: .actionSheet)\n\nlet cancelAction = UIAlertAction(title: \"\u53d6\u6d88\", style: .cancel, handler: nil)\nlet okAction = UIAlertAction(title: \"\u78ba\u5b9a\", style: .default) { action in\n    print(\"\u4f7f\u7528\u8005\u9078\u64c7\u4e86\u78ba\u5b9a\")\n}\n\nactionSheet.addAction(cancelAction)\nactionSheet.addAction(okAction)\n\npresent(actionSheet, animated: true, completion: nil)\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528 <strong>UIAlertController<\/strong> \u548c <strong>ActionSheet<\/strong> \u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u7684\u5e38\u898b\u554f\u984c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u672a\u6b63\u78ba\u986f\u793a\uff1a <\/strong>\u78ba\u4fdd\u60a8\u5728\u4e3b\u57f7\u884c\u7dd2\u4e2d\u547c\u53eb <code>present<\/code> \u65b9\u6cd5\u3002<\/li>\n<li><strong>\u884c\u70ba\u4e0d\u5982\u9810\u671f\uff1a <\/strong>\u6aa2\u67e5\u52d5\u4f5c\u7684 <code>handler<\/code> \u662f\u5426\u6b63\u78ba\u8a2d\u7f6e\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u60a8\u53ef\u4ee5\u9032\u4e00\u6b65\u64f4\u5c55\u9019\u4e9b\u529f\u80fd\uff0c\u6dfb\u52a0\u66f4\u591a\u52d5\u4f5c\u6216\u6839\u64da\u4f7f\u7528\u8005\u7684\u9078\u64c7\u57f7\u884c\u4e0d\u540c\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u6839\u64da\u4f7f\u7528\u8005\u7684\u9078\u64c7\u986f\u793a\u4e0d\u540c\u7684\u8996\u5716\u6216\u57f7\u884c\u7279\u5b9a\u7684\u908f\u8f2f\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>Swift \u7684 <strong>UIAlertController<\/strong> \u548c <strong>ActionSheet<\/strong> \u662f\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\uff0c\u80fd\u5920\u63d0\u5347\u61c9\u7528\u7a0b\u5f0f\u7684\u4f7f\u7528\u8005\u4e92\u52d5\u9ad4\u9a57\u3002\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u4e0d\u540c\u60c5\u5883\u9078\u64c7\u5408\u9069\u7684\u65b9\u5f0f\u4f86\u63d0\u4f9b\u591a\u6a23\u7684\u9078\u64c7\uff0c\u8b93\u4f7f\u7528\u8005\u5728\u61c9\u7528\u7a0b\u5f0f\u4e2d\u64c1\u6709\u66f4\u597d\u7684\u9ad4\u9a57\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-UIAlertController-ActionSheet-\ud83d\udca1\u9078\u64c7\u7684\u6642\u5019\u6709\u591a\u7a2e\u65b9\u6cd5\uff01_1675400242.927549.webp\" alt=\"Swift UIAlertController + ActionSheet \u6559\u5b78\" title=\"Swift UIAlertController\u3001ActionSheet\u3001\u9078\u64c7\u591a\u6a23\u6027\u3001\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. \u5982\u4f55\u5728 UIAlertController \u4e2d\u6dfb\u52a0\u66f4\u591a\u52d5\u4f5c\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>addAction<\/code> \u65b9\u6cd5\u591a\u6b21\u6dfb\u52a0 <code>UIAlertAction<\/code>\uff0c\u4ee5\u4fbf\u63d0\u4f9b\u591a\u500b\u9078\u64c7\u7d66\u4f7f\u7528\u8005\u3002<\/p>\n<h3>2. ActionSheet \u53ef\u4ee5\u5728 iPad \u4e0a\u4f7f\u7528\u55ce\uff1f<\/h3>\n<p>\u662f\u7684\uff0c\u4f7f\u7528 <strong>ActionSheet<\/strong> \u6642\uff0c\u60a8\u9700\u8981\u5728 iPad \u4e0a\u6307\u5b9a <code>popoverPresentationController<\/code> \u7684\u4f86\u6e90\uff0c\u4ee5\u907f\u514d\u932f\u8aa4\u3002<\/p>\n<h3>3. \u5982\u4f55\u81ea\u8a02 UIAlertController \u7684\u6a23\u5f0f\uff1f<\/h3>\n<p>Swift \u7684 <strong>UIAlertController<\/strong> \u63d0\u4f9b\u57fa\u672c\u7684\u6a23\u5f0f\u9078\u9805\uff0c\u60a8\u53ef\u4ee5\u900f\u904e\u4fee\u6539\u5176\u6a19\u984c\u548c\u8a0a\u606f\u4f86\u9054\u6210\u7c21\u55ae\u7684\u81ea\u8a02\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aSwiftUIAlertController+ActionSheet\u662f\u4e00\u7a2e\u7c21\u55ae\u53c8\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8b93\u4f60\u5728\u4f7f\u7528Swift\u7a0b\u5f0f\u8a9e\u8a00\u6642\uff0c\u66f4\u52a0\u8f15\u9b06\u5730\u9078\u64c7\u4e0d\u540c\u7684\u65b9\u6cd5\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528SwiftUIAlertController+ActionSheet\u4f86\u589e\u52a0\u9078\u64c7\u7684\u591a\u6a23\u6027\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u7c21\u55ae\u7684\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\u4f86\u8b93\u4f60\u66f4\u5bb9\u6613\u7406\u89e3\u3002<\/p>\n","protected":false},"author":1,"featured_media":6998,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-7000","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-UIAlertController-ActionSheet-\ud83d\udca1\u9078\u64c7\u7684\u6642\u5019\u6709\u591a\u7a2e\u65b9\u6cd5\uff01_1675400242.927549.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1OU","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7000","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=7000"}],"version-history":[{"count":6,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7000\/revisions"}],"predecessor-version":[{"id":13597,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7000\/revisions\/13597"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6998"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}