{"id":7696,"date":"2025-05-31T13:31:43","date_gmt":"2025-06-05T06:25:43","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7696"},"modified":"2025-06-05T13:31:43","modified_gmt":"2025-06-05T06:25:43","slug":"https-badgameshow-com-steven-491","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-491\/","title":{"rendered":"\u5728 SwiftUI \u4e2d\u4f7f\u7528 NavigationView \u548c NavigationLink\uff1a2025 \u6700\u65b0\u6559\u5b78\u6307\u5357"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, NavigationView, NavigationLink, SwiftUI\"><\/p>\n<h2>\u5f15\u8a00<\/h2>\n<p>SwiftUI \u662f Apple \u5728 WWDC 2019 \u63a8\u51fa\u7684\u65b0\u6846\u67b6\uff0c\u96a8\u8457\u4e0d\u65b7\u7684\u66f4\u65b0\u8207\u6f14\u9032\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u5feb\u901f\u3001\u66f4\u76f4\u89c0\u5730\u958b\u767c\u8de8\u5e73\u53f0\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u672c\u7bc7\u6587\u7ae0\u5c07\u6df1\u5165\u4ecb\u7d39\u5982\u4f55\u5728 SwiftUI \u4e2d\u4f7f\u7528 NavigationView \u548c NavigationLink\uff0c\u4e26\u63d0\u4f9b2025\u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\uff0c\u5e6b\u52a9\u60a8\u5feb\u901f\u5be6\u73fe\u61c9\u7528\u7a0b\u5f0f\u7684\u5c0e\u822a\u529f\u80fd\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f NavigationView \u548c NavigationLink<\/h2>\n<p>NavigationView \u548c NavigationLink \u662f SwiftUI \u4e2d\u7684\u5169\u500b\u91cd\u8981\u5143\u4ef6\uff0c\u5b83\u5011\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u51fa\u61c9\u7528\u7a0b\u5f0f\u7684\u5c0e\u822a\u529f\u80fd\u3002 <\/p>\n<p>&#8211; **NavigationView**\uff1a\u4f5c\u70ba\u4e00\u500b\u5bb9\u5668\uff0c\u80fd\u5920\u5305\u542b\u591a\u500b NavigationLink\uff0c\u63d0\u4f9b\u4e00\u500b\u5c0e\u822a\u7684\u7d50\u69cb\u3002<br \/>\n&#8211; **NavigationLink**\uff1a\u4f5c\u70ba\u4e00\u500b\u6309\u9215\uff0c\u5141\u8a31\u4f7f\u7528\u8005\u9ede\u64ca\u5f8c\u8df3\u8f49\u5230\u53e6\u4e00\u500b\u9801\u9762\u3002<\/p>\n<h2>\u5982\u4f55\u5728 SwiftUI \u4e2d\u4f7f\u7528 NavigationView \u548c NavigationLink<\/h2>\n<p>\u5728 SwiftUI \u4e2d\u4f7f\u7528 NavigationView \u548c NavigationLink \u975e\u5e38\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nimport SwiftUI<\/p>\n<p>struct ContentView: View {<br \/>\n    var body: some View {<br \/>\n        NavigationView {<br \/>\n            NavigationLink(destination: YourView()) {<br \/>\n                Text(&#8220;Go to YourView&#8221;)<br \/>\n                    .padding()<br \/>\n                    .background(Color.blue)<br \/>\n                    .foregroundColor(.white)<br \/>\n                    .cornerRadius(8)<br \/>\n            }<br \/>\n            .navigationTitle(&#8220;Main View&#8221;) \/\/ \u8a2d\u5b9a\u5c0e\u822a\u6a19\u984c<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>struct YourView: View {<br \/>\n    var body: some View {<br \/>\n        Text(&#8220;Welcome to YourView&#8221;)<br \/>\n            .font(.largeTitle)<br \/>\n            .padding()<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86 NavigationView \u548c NavigationLink \u4f86\u958b\u767c\u61c9\u7528\u7a0b\u5f0f\u7684\u5c0e\u822a\u529f\u80fd\u3002\u7576\u4f7f\u7528\u8005\u9ede\u64ca &#8220;Go to YourView&#8221; \u7684\u6587\u5b57\u6642\uff0c\u5c07\u6703\u8df3\u8f49\u5230 YourView \u9801\u9762\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528 NavigationView \u548c NavigationLink \u6642\uff0c\u60a8\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u554f\u984c\uff1a<\/p>\n<p>1. **\u7121\u6cd5\u8df3\u8f49\u5230\u76ee\u6a19\u8996\u5716**\uff1a<br \/>\n   &#8211; \u78ba\u8a8d\u60a8\u7684\u76ee\u6a19\u8996\u5716\uff08\u5982 YourView\uff09\u662f\u5426\u6b63\u78ba\u5b9a\u7fa9\u4e26\u4e14\u6c92\u6709\u932f\u8aa4\u3002<br \/>\n   &#8211; \u6aa2\u67e5 NavigationView \u662f\u5426\u6b63\u78ba\u5305\u88f9\u4e86 NavigationLink\u3002<\/p>\n<p>2. **\u5c0e\u822a\u6a19\u984c\u672a\u986f\u793a**\uff1a<br \/>\n   &#8211; \u78ba\u4fdd\u5728 NavigationView \u4e2d\u4f7f\u7528 `.navigationTitle()` \u8a2d\u5b9a\u5c0e\u822a\u6a19\u984c\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 NavigationView \u548c NavigationLink \u5efa\u69cb\u66f4\u8907\u96dc\u7684\u5c0e\u822a\u7d50\u69cb\uff0c\u4f8b\u5982\u5d4c\u5957\u5c0e\u822a\u3002\u9019\u5c0d\u65bc\u591a\u5c64\u7d1a\u7684\u61c9\u7528\u7a0b\u5f0f\u7279\u5225\u6709\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nNavigationView {<br \/>\n    NavigationLink(destination: SecondView()) {<br \/>\n        Text(&#8220;Go to Second View&#8221;)<br \/>\n    }<br \/>\n}<\/p>\n<p>struct SecondView: View {<br \/>\n    var body: some View {<br \/>\n        VStack {<br \/>\n            Text(&#8220;This is the second view&#8221;)<br \/>\n            NavigationLink(destination: ThirdView()) {<br \/>\n                Text(&#8220;Go to Third View&#8221;)<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>struct ThirdView: View {<br \/>\n    var body: some View {<br \/>\n        Text(&#8220;Welcome to the Third View&#8221;)<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5f9e\u7b2c\u4e00\u500b\u8996\u5716\u8df3\u8f49\u5230\u7b2c\u4e8c\u500b\u8996\u5716\uff0c\u7136\u5f8c\u518d\u5f9e\u7b2c\u4e8c\u500b\u8996\u5716\u8df3\u8f49\u5230\u7b2c\u4e09\u500b\u8996\u5716\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u69cb\u5efa\u591a\u5c64\u7d1a\u7684\u5c0e\u822a\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 SwiftUI \u4e2d\u4f7f\u7528 NavigationView \u548c NavigationLink \u4f86\u958b\u767c\u61c9\u7528\u7a0b\u5f0f\u7684\u5c0e\u822a\u529f\u80fd\u3002\u900f\u904e\u9019\u4e9b\u5143\u4ef6\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u69cb\u5efa\u51fa\u76f4\u89c0\u7684\u5c0e\u822a\u9ad4\u9a57\uff0c\u8b93\u7528\u6236\u7684\u64cd\u4f5c\u66f4\u52a0\u6d41\u66a2\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. NavigationView \u53ef\u4ee5\u5d4c\u5957\u4f7f\u7528\u55ce\uff1f<\/h3>\n<p>\u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u5728 NavigationView \u4e2d\u5d4c\u5957\u5176\u4ed6 NavigationView\uff0c\u9019\u6a23\u53ef\u4ee5\u69cb\u5efa\u66f4\u8907\u96dc\u7684\u5c0e\u822a\u7d50\u69cb\u3002<\/p>\n<h3>2. \u5982\u4f55\u81ea\u5b9a\u7fa9 NavigationLink \u7684\u6a23\u5f0f\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 SwiftUI \u63d0\u4f9b\u7684\u4fee\u98fe\u7b26\uff08\u5982 padding\u3001background\u3001foregroundColor\uff09\u4f86\u81ea\u5b9a\u7fa9 NavigationLink \u7684\u6a23\u5f0f\u3002<\/p>\n<h3>3. \u662f\u5426\u53ef\u4ee5\u5728 NavigationLink \u4e2d\u50b3\u905e\u6578\u64da\uff1f<\/h3>\n<p>\u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u5728 NavigationLink \u4e2d\u50b3\u905e\u6578\u64da\u81f3\u76ee\u6a19\u8996\u5716\uff0c\u9019\u6a23\u53ef\u4ee5\u6839\u64da\u4e0a\u4e0b\u6587\u986f\u793a\u4e0d\u540c\u7684\u5167\u5bb9\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/\u5728-SwiftUI-\u4e2d\u4f7f\u7528-NavigationView-\u548c-NavigationLink_1676960378.23718.webp\" alt=\"\u5728 SwiftUI \u4e2d\u4f7f\u7528 NavigationView \u548c NavigationLink\" title=\"SwiftUI, NavigationView, NavigationLink, \u5c0e\u822a, \u8996\u5716\" width=\"1200\" height=\"628\"\/><br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728SwiftUI\u4e2d\u4f7f\u7528NavigationView\u548cNavigationLink\uff0c\u8b93\u4f60\u53ef\u4ee5\u8f15\u9b06\u5730\u5c0e\u822a\u5230\u4e0d\u540c\u7684\u8996\u5716\uff0c\u4e26\u66f4\u597d\u5730\u7ba1\u7406\u61c9\u7528\u7a0b\u5e8f\u7684\u5c0e\u822a\u7d50\u69cb\u3002<\/p>\n","protected":false},"author":1,"featured_media":7695,"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-7696","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\/\u5728-SwiftUI-\u4e2d\u4f7f\u7528-NavigationView-\u548c-NavigationLink_1676960378.23718.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-208","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7696","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=7696"}],"version-history":[{"count":3,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7696\/revisions"}],"predecessor-version":[{"id":13585,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7696\/revisions\/13585"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7695"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}