{"id":7591,"date":"2025-05-31T14:09:55","date_gmt":"2025-06-05T06:19:55","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7591"},"modified":"2025-06-05T14:09:55","modified_gmt":"2025-06-05T06:19:55","slug":"https-badgameshow-com-steven-447","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-447\/","title":{"rendered":"2025 \u6700\u65b0 Swift \u5c0e\u822a\u5217(UINavigationController) \u6559\u5b78 \u2013 \u5b8c\u6574\u6307\u5357\u8207\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UINavigationController, iOS, \u6559\u5b78, \u7a0b\u5f0f\u8a2d\u8a08\"><\/p>\n<h1>2025 \u6700\u65b0 Swift \u5c0e\u822a\u5217(UINavigationController) \u6559\u5b78 \u2013 \u5b8c\u6574\u6307\u5357\u8207\u6700\u4f73\u5be6\u8e10<\/h1>\n<p>Swift \u5c0e\u822a\u5217 (UINavigationController) \u662f iOS App \u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u5143\u4ef6\uff0c\u80fd\u5920\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u4e26\u63d0\u4f9b\u66f4\u6d41\u66a2\u7684\u5c0e\u822a\u529f\u80fd\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 <code>UINavigationController<\/code>\uff0c\u4e26\u5206\u4eab\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\uff0c\u8b93\u4f60\u7684 App \u66f4\u52a0\u6613\u7528\u4e14\u529f\u80fd\u5f37\u5927\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f Swift \u5c0e\u822a\u5217(UINavigationController)?<\/h2>\n<p><code>UINavigationController<\/code> \u662f\u4e00\u7a2e\u5bb9\u5668\u8996\u5716\u63a7\u5236\u5668\uff0c\u5c08\u9580\u7528\u65bc\u7ba1\u7406\u4e00\u7cfb\u5217\u7684\u8996\u5716\u63a7\u5236\u5668\u3002\u900f\u904e\u5c0e\u822a\u5217\uff0c\u4f60\u53ef\u4ee5\u8f15\u9b06\u5730\u5728\u4e0d\u540c\u7684\u8996\u5716\u4e4b\u9593\u9032\u884c\u5207\u63db\uff0c\u4e26\u4e14\u4fdd\u6301\u826f\u597d\u7684\u7528\u6236\u754c\u9762\u7d50\u69cb\u3002\u4f7f\u7528\u5c0e\u822a\u5217\u7684\u597d\u8655\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u7c21\u5316\u8996\u5716\u7ba1\u7406\uff1a\u81ea\u52d5\u8655\u7406\u8996\u5716\u63a7\u5236\u5668\u7684\u5806\u758a\u3002<\/li>\n<li>\u5167\u5efa\u7684\u8fd4\u56de\u529f\u80fd\uff1a\u7528\u6236\u53ef\u4ee5\u8f15\u9b06\u5730\u8fd4\u56de\u5230\u4e0a\u500b\u8996\u5716\u3002<\/li>\n<li>\u81ea\u8a02\u5c0e\u822a\u6a19\u984c\u548c\u6309\u9215\uff0c\u63d0\u9ad8\u7528\u6236\u4e92\u52d5\u6027\u3002<\/li>\n<\/ul>\n<h2>\u5982\u4f55\u4f7f\u7528 UINavigationController<\/h2>\n<h3>\u6b65\u9a5f 1: \u5275\u5efa UINavigationController<\/h3>\n<p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u4f60\u7684 App \u4e2d\u5275\u5efa\u4e00\u500b <code>UINavigationController<\/code> \u5be6\u4f8b\u3002\u9019\u53ef\u4ee5\u901a\u904e\u7a0b\u5f0f\u78bc\u6216 Storyboard \u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u662f\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>import UIKit\n\nclass ViewController: UIViewController {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        let secondViewController = SecondViewController()\n        let navigationController = UINavigationController(rootViewController: secondViewController)\n        navigationController.modalPresentationStyle = .fullScreen\n        present(navigationController, animated: true, completion: nil)\n    }\n}\n<\/code><\/pre>\n<h3>\u6b65\u9a5f 2: \u63a8\u5165\u65b0\u8996\u5716\u63a7\u5236\u5668<\/h3>\n<p>\u8981\u5728\u5c0e\u822a\u5217\u4e2d\u63a8\u5165\u65b0\u7684\u8996\u5716\u63a7\u5236\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>pushViewController(_:animated:)<\/code> \u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code>let newViewController = NewViewController()\nnavigationController?.pushViewController(newViewController, animated: true)\n<\/code><\/pre>\n<h3>\u6b65\u9a5f 3: \u8fd4\u56de\u4e0a\u500b\u8996\u5716\u63a7\u5236\u5668<\/h3>\n<p>\u7528\u6236\u53ef\u4ee5\u901a\u904e\u5c0e\u822a\u5217\u7684\u8fd4\u56de\u6309\u9215\u8fd4\u56de\u4e0a\u500b\u8996\u5716\u3002\u4f60\u4e5f\u53ef\u4ee5\u624b\u52d5\u8abf\u7528 <code>popViewController(animated:)<\/code> \u65b9\u6cd5\u4f86\u5be6\u73fe\uff1a<\/p>\n<pre><code>navigationController?.popViewController(animated: true)\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528 <code>UINavigationController<\/code> \u6642\uff0c\u5e38\u898b\u7684\u932f\u8aa4\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u7121\u6cd5\u8fd4\u56de\u4e0a\u500b\u8996\u5716\uff1a<\/strong> \u78ba\u4fdd\u4f60\u6b63\u5728\u6b63\u78ba\u5730\u63a8\u5165\u548c\u5f48\u51fa\u8996\u5716\u63a7\u5236\u5668\u3002<\/li>\n<li><strong>\u5c0e\u822a\u5217\u4e0d\u986f\u793a\uff1a<\/strong> \u78ba\u8a8d\u4f60\u7684\u8996\u5716\u63a7\u5236\u5668\u662f\u5d4c\u5165\u5728 <code>UINavigationController<\/code> \u4e2d\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u4f60\u53ef\u4ee5\u5c07 <code>UINavigationController<\/code> \u8207\u5176\u4ed6\u8996\u5716\u63a7\u5236\u5668\u7d50\u5408\u4f7f\u7528\uff0c\u4f8b\u5982 <code>UITableViewController<\/code>\uff0c\u4ee5\u5275\u5efa\u66f4\u8907\u96dc\u7684\u61c9\u7528\u7a0b\u5f0f\u67b6\u69cb\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7d50\u5408 <code>UINavigationController<\/code> \u548c <code>UITableViewController<\/code> \u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>import UIKit\n\nclass MainTableViewController: UITableViewController {\n    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n        return 10\n    }\n\n    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n        let cell = tableView.dequeueReusableCell(withIdentifier: \"Cell\", for: indexPath)\n        cell.textLabel?.text = \"Item \\(indexPath.row)\"\n        return cell\n    }\n\n    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\n        let detailViewController = DetailViewController()\n        navigationController?.pushViewController(detailViewController, animated: true)\n    }\n}\n<\/code><\/pre>\n<h2>\u63a8\u85a6\u95b1\u8b80\u6587\u7ae0<\/h2>\n<p>\u82e5\u60f3\u9032\u4e00\u6b65\u5b78\u7fd2 <code>UINavigationController<\/code>\uff0c\u4f60\u53ef\u4ee5\u53c3\u8003\u4ee5\u4e0b\u8cc7\u6e90\uff1a<\/p>\n<pre><code>\n<a href=\"https:\/\/www.raywenderlich.com\/711-uinavigationcontroller-tutorial-getting-started\" target=\"_blank\" rel=\"noopener\">UINavigationController \u6559\u5b78 \u2013 \u5165\u9580<\/a><br>\n<a href=\"https:\/\/www.appcoda.com.tw\/uinavigationcontroller-programming-guide\/\" target=\"_blank\" rel=\"noopener\">UINavigationController \u7a0b\u5f0f\u6307\u5357<\/a><br>\n<a href=\"https:\/\/medium.com\/@danielgalasko\/a-comprehensive-guide-to-uinavigationcontroller-8a63cbbd6efb\" target=\"_blank\" rel=\"noopener\">UINavigationController \u7d9c\u5408\u6307\u5357<\/a><br>\n<a href=\"https:\/\/www.hackingwithswift.com\/example-code\/uikit\/how-to-use-uinavigationcontroller-with-uitableviewcontroller\" target=\"_blank\" rel=\"noopener\">\u5982\u4f55\u4f7f\u7528 UINavigationController \u8207 UITableViewController<\/a><br>\n<a href=\"https:\/\/www.hackingwithswift.com\/example-code\/uikit\/how-to-push-view-controllers-onto-a-navigation-controller-using-storyboards\" target=\"_blank\" rel=\"noopener\">\u5982\u4f55\u4f7f\u7528 Storyboards \u5c07 View Controllers \u63a8\u5165 UINavigationController<\/a>\n<\/code><\/pre>\n<h2>\u63a8\u85a6\u5b78\u7fd2 Youtube \u5f71\u7247<\/h2>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=2t3Km6seEAY\" target=\"_blank\" rel=\"noopener\">09 \u5c0e\u822a\u63a7\u5236\u5668\u7684\u57fa\u672c\u4f7f\u7528<\/a><br \/>\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/2t3Km6seEAY\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5c0e\u822a\u5217UINavigationController-\ud83d\uddfa\u5b78\u7fd2\u6559\u5b78-\u2013-\u638c\u63e1\u5982\u4f55\u4f7f\u7528_1675477698.867038.webp\" alt=\"Swift \u5c0e\u822a\u5217(UINavigationController) \ud83d\uddfa\u5b78\u7fd2\u6559\u5b78 \u2013 \u638c\u63e1\u5982\u4f55\u4f7f\u7528\" title=\"Swift\u5c0e\u822a\u5217\u3001UINavigationController\u3001\u5c0e\u822a\u61c9\u7528\u7a0b\u5e8f\u3001\u5c0e\u822a\u63a7\u5236\u5668\u3001\u8996\u5716\u63a7\u5236\u5668\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>\u5e38\u898b\u554f\u984c\u89e3\u7b54 (Q&#038;A)<\/h2>\n<h3>Q1: \u5982\u4f55\u5728 UINavigationController \u4e2d\u8a2d\u7f6e\u81ea\u5b9a\u7fa9\u7684\u5c0e\u822a\u6309\u9215\uff1f<\/h3>\n<p>A1: \u4f60\u53ef\u4ee5\u901a\u904e <code>navigationItem.rightBarButtonItem<\/code> \u548c <code>navigationItem.leftBarButtonItem<\/code> \u5c6c\u6027\u4f86\u8a2d\u7f6e\u81ea\u5b9a\u7fa9\u7684\u5c0e\u822a\u6309\u9215\u3002<\/p>\n<h3>Q2: UINavigationController \u662f\u5426\u652f\u63f4\u591a\u5c64\u5d4c\u5957\u7684\u5c0e\u822a\uff1f<\/h3>\n<p>A2: \u662f\u7684\uff0c<code>UINavigationController<\/code> \u652f\u63f4\u591a\u5c64\u5d4c\u5957\u7684\u5c0e\u822a\uff0c\u4f60\u53ef\u4ee5\u5728\u6bcf\u500b\u8996\u5716\u63a7\u5236\u5668\u4e2d\u63a8\u5165\u65b0\u7684\u8996\u5716\u63a7\u5236\u5668\u3002<\/p>\n<h3>Q3: \u5982\u4f55\u5728 UINavigationController \u4e2d\u4f7f\u7528\u904e\u6e21\u52d5\u756b\uff1f<\/h3>\n<p>A3: \u4f60\u53ef\u4ee5\u901a\u904e\u81ea\u5b9a\u7fa9\u7684\u52d5\u756b\u63a7\u5236\u5668\u4f86\u5be6\u73fe\u904e\u6e21\u52d5\u756b\uff0c\u4e26\u5728\u63a8\u5165\u6216\u5f48\u51fa\u8996\u5716\u63a7\u5236\u5668\u6642\u4f7f\u7528 <code>UIViewControllerAnimatedTransitioning<\/code> \u5354\u8b70\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39Swift\u5c0e\u822a\u5217\uff08UINavigationController\uff09\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u5efa\u7acb\u4e00\u500b\u5b8c\u6574\u7684\u5c0e\u822a\u61c9\u7528\u7a0b\u5e8f\u3002\u8b80\u8005\u5c07\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528\u5c0e\u822a\u63a7\u5236\u5668\uff0c\u4ee5\u53ca\u5982\u4f55\u5c07\u5b83\u8207\u5176\u4ed6\u63a7\u5236\u5668\u548c\u8996\u5716\u63a7\u5236\u5668\u7d50\u5408\u4f7f\u7528\u3002<\/p>\n","protected":false},"author":1,"featured_media":7590,"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-7591","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-\u5c0e\u822a\u5217UINavigationController-\ud83d\uddfa\u5b78\u7fd2\u6559\u5b78-\u2013-\u638c\u63e1\u5982\u4f55\u4f7f\u7528_1675477698.867038.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Yr","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7591","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=7591"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7591\/revisions"}],"predecessor-version":[{"id":13451,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7591\/revisions\/13451"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7590"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}