{"id":7483,"date":"2025-05-30T12:58:52","date_gmt":"2025-06-05T05:41:51","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7483"},"modified":"2025-06-05T12:58:52","modified_gmt":"2025-06-05T05:41:51","slug":"https-badgameshow-com-steven-412","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-412\/","title":{"rendered":"Swift \u5f48\u51fa\u63d0\u793a\u6846\u6559\u5b78\uff1a2025 \u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u5f48\u51fa\u63d0\u793a\u6846, UIAlertController\"><\/p>\n<h2>\u4ec0\u9ebc\u662f Swift \u5f48\u51fa\u63d0\u793a\u6846\uff1f<\/h2>\n<p>Swift \u5f48\u51fa\u63d0\u793a\u6846\u662f\u4e00\u7a2e\u5f48\u51fa\u5f0f\u8996\u7a97\uff0c\u53ef\u4ee5\u5728 iOS \u61c9\u7528\u7a0b\u5f0f\u4e2d\u986f\u793a\u8a0a\u606f\uff0c\u4e26\u8981\u6c42\u4f7f\u7528\u8005\u505a\u51fa\u6c7a\u5b9a\u3002\u5b83\u53ef\u4ee5\u7528\u4f86\u63d0\u9192\u4f7f\u7528\u8005\u505a\u51fa\u6b63\u78ba\u7684\u6c7a\u5b9a\uff0c\u6216\u8005\u63d0\u4f9b\u91cd\u8981\u7684\u8cc7\u8a0a\u3002\u900f\u904e\u4f7f\u7528 <code>UIAlertController<\/code>\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5be6\u4f5c\u9019\u7a2e\u529f\u80fd\uff0c\u589e\u5f37\u7528\u6236\u4e92\u52d5\u3002<\/p>\n<h2>\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528\u5f48\u51fa\u63d0\u793a\u6846\uff1f<\/h2>\n<p>\u5728 Swift \u4e2d\u4f7f\u7528\u5f48\u51fa\u63d0\u793a\u6846\u975e\u5e38\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 <code>UIAlertController<\/code> \u985e\u5225\u4f86\u5efa\u7acb\u5f48\u51fa\u63d0\u793a\u6846\u7684\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u5efa\u7acb <code>UIAlertController<\/code> \u5be6\u4f8b\uff0c\u6307\u5b9a\u6a19\u984c\u548c\u8a0a\u606f\u3002<\/li>\n<li>\u6dfb\u52a0\u4e00\u500b\u6216\u591a\u500b <code>UIAlertAction<\/code>\uff0c\u4ee5\u97ff\u61c9\u4f7f\u7528\u8005\u7684\u9078\u64c7\u3002<\/li>\n<li>\u5c07\u63d0\u793a\u6846\u5448\u73fe\u7d66\u7576\u524d\u7684\u8996\u5716\u63a7\u5236\u5668\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528\u5f48\u51fa\u63d0\u793a\u6846\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let alertController = UIAlertController(title: \"\u63d0\u793a\", message: \"\u9019\u662f\u4e00\u500b\u63d0\u793a\u6846\", preferredStyle: .alert)\n\nlet okAction = UIAlertAction(title: \"\u78ba\u5b9a\", style: .default) { action in\n    \/\/ \u5728\u9019\u88e1\u53ef\u4ee5\u6dfb\u52a0\u6309\u4e0b\u78ba\u5b9a\u5f8c\u7684\u884c\u70ba\n    print(\"\u4f7f\u7528\u8005\u6309\u4e0b\u78ba\u5b9a\")\n}\nalertController.addAction(okAction)\n\nlet cancelAction = UIAlertAction(title: \"\u53d6\u6d88\", style: .cancel) { action in\n    \/\/ \u5728\u9019\u88e1\u53ef\u4ee5\u6dfb\u52a0\u6309\u4e0b\u53d6\u6d88\u5f8c\u7684\u884c\u70ba\n    print(\"\u4f7f\u7528\u8005\u6309\u4e0b\u53d6\u6d88\")\n}\nalertController.addAction(cancelAction)\n\nself.present(alertController, animated: true, completion: nil)\n<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5efa\u7acb\u4e00\u500b\u5f48\u51fa\u63d0\u793a\u6846\uff0c\u4e26\u986f\u793a\u78ba\u5b9a\u548c\u53d6\u6d88\u5169\u500b\u6309\u9215\u3002\u7576\u4f7f\u7528\u8005\u6309\u4e0b\u5176\u4e2d\u4e00\u500b\u6309\u9215\u6642\uff0c\u76f8\u61c9\u7684\u884c\u70ba\u5c31\u6703\u88ab\u89f8\u767c\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u8207\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u4f7f\u7528\u5f48\u51fa\u63d0\u793a\u6846\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u554f\u984c\uff1a<\/p>\n<ul>\n<li><strong>\u63d0\u793a\u6846\u4e0d\u986f\u793a\uff1a<\/strong>\u8acb\u78ba\u8a8d\u60a8\u5728\u6b63\u78ba\u7684\u8996\u5716\u63a7\u5236\u5668\u4e0a\u8abf\u7528 <code>present<\/code> \u65b9\u6cd5\u3002<\/li>\n<li><strong>\u6309\u9215\u7121\u53cd\u61c9\uff1a<\/strong>\u78ba\u4fdd\u60a8\u6b63\u78ba\u914d\u7f6e <code>UIAlertAction<\/code> \u7684\u8655\u7406\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<p>\u9075\u5faa\u6700\u4f73\u5be6\u8e10\u662f\u78ba\u4fdd\u826f\u597d\u7528\u6236\u9ad4\u9a57\u7684\u95dc\u9375\u3002\u78ba\u4fdd\u63d0\u793a\u6846\u7684\u4f7f\u7528\u4e0d\u6703\u904e\u65bc\u983b\u7e41\uff0c\u4ee5\u514d\u6253\u64fe\u7528\u6236\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u63d0\u793a\u6846\u5916\uff0c\u60a8\u9084\u53ef\u4ee5\u4f7f\u7528 <code>UIAlertController<\/code> \u5275\u5efa\u5176\u4ed6\u985e\u578b\u7684\u5f48\u51fa\u8996\u7a97\uff0c\u4f8b\u5982\uff1a\u884c\u52d5\u8868\u55ae\uff08Action Sheet\uff09\u548c\u6587\u672c\u8f38\u5165\u63d0\u793a\u6846\u3002\u9019\u4f7f\u5f97\u63d0\u793a\u6846\u7684\u61c9\u7528\u66f4\u52a0\u9748\u6d3b\u8207\u591a\u6a23\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>Swift \u662f\u4e00\u7a2e\u5f37\u5927\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u9069\u7528\u65bc\u5feb\u901f\u958b\u767c\u529f\u80fd\u5f37\u5927\u7684 iOS \u61c9\u7528\u7a0b\u5f0f\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528\u5f48\u51fa\u63d0\u793a\u6846\uff0c\u4e26\u63d0\u4f9b\u4e86\u76f8\u95dc\u7684\u793a\u4f8b\u7a0b\u5f0f\u78bc\u4ee5\u53ca\u932f\u8aa4\u6392\u9664\u7684\u5efa\u8b70\u3002\u5e0c\u671b\u9019\u4e9b\u8cc7\u8a0a\u80fd\u5e6b\u52a9\u60a8\u5728\u958b\u767c\u904e\u7a0b\u4e2d\u66f4\u52a0\u5f97\u5fc3\u61c9\u624b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5f48\u51fa\u63d0\u793a\u6846-\ud83d\udca1\ud83d\udd14_1675476607.828322.webp\" alt=\"Swift \u5f48\u51fa\u63d0\u793a\u6846 \ud83d\udca1\ud83d\udd14\" title=\"Swift \u63d0\u793a\u6846, UIAlertController, \u5f48\u51fa\u63d0\u793a\u6846, Swift \u63d0\u793a\u6846\u529f\u80fd, Swift \u63d0\u793a\u6846\u7a0b\u5f0f\" 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\u63d0\u793a\u6846\u4e2d\u6dfb\u52a0\u591a\u500b\u6309\u9215\uff1f<\/h3>\n<p>\u53ef\u4ee5\u901a\u904e\u591a\u6b21\u8abf\u7528 <code>addAction<\/code> \u65b9\u6cd5\u4f86\u70ba\u63d0\u793a\u6846\u6dfb\u52a0\u591a\u500b\u6309\u9215\uff0c\u4e26\u70ba\u6bcf\u500b\u6309\u9215\u8a2d\u7f6e\u4e0d\u540c\u7684\u8655\u7406\u7a0b\u5e8f\u3002<\/p>\n<h3>2. \u5982\u4f55\u4f7f\u7528 <code>UIAlertController<\/code> \u5275\u5efa\u884c\u52d5\u8868\u55ae\uff1f<\/h3>\n<p>\u884c\u52d5\u8868\u55ae\u53ef\u901a\u904e\u5c07 <code>preferredStyle<\/code> \u8a2d\u5b9a\u70ba <code>.actionSheet<\/code> \u4f86\u5275\u5efa\uff0c\u4e26\u5728\u5176\u4e2d\u6dfb\u52a0\u5fc5\u8981\u7684 <code>UIAlertAction<\/code>\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981(Description):\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684UIAlertController\u4f86\u5f48\u51fa\u63d0\u793a\u6846\uff0c\u8b93\u4f60\u7684App\u53ef\u4ee5\u66f4\u52a0\u5b8c\u5584\uff0c\u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u66f4\u52a0\u4e86\u89e3\u4f60\u7684App\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":7481,"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-7483","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-\u5f48\u51fa\u63d0\u793a\u6846-\ud83d\udca1\ud83d\udd14_1675476607.828322.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1WH","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7483","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=7483"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7483\/revisions"}],"predecessor-version":[{"id":13433,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7483\/revisions\/13433"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7481"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}