Creating a navigationController programmatically (Swift)(以编程方式创建一个 navigationController (Swift))
问题描述
我一直在尝试以编程方式重做我的应用程序上的工作.(不使用情节提要)
I've been trying to redo the work on my app programmatically. (Without the use of storyboards)
我差不多完成了,除了手动制作导航控制器.
I'm almost done, except making the navigation controller manually.
我一直在做一些研究,但找不到任何手动实现此功能的文档.(我开始将应用程序制作为单视图应用程序)
I've been doing some research but I can't find any documentation of implementing this manually. (I started making the app as a Single View Application)
目前,我只有 1 个视图控制器.当然还有 appDelegate
Currently, I only have 1 viewcontroller. And of course the appDelegate
导航控制器将在应用程序的所有页面中使用.
The navigation Controller, will be used throughout all pages in the application.
如果有人可以帮助我,或者发送指向一些适当文档的链接以便以编程方式执行此操作,我们将不胜感激.
If anyone could help me out, or send a link to some proper documentation for doing this programmatically it would be greatly appreciated.
我忘了提到它是在 Swift 中的.
I forgot to mention it's in Swift.
推荐答案
Swift 1, 2:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var nav1 = UINavigationController()
var mainView = ViewController(nibName: nil, bundle: nil) //ViewController = Name of your controller
nav1.viewControllers = [mainView]
self.window!.rootViewController = nav1
self.window?.makeKeyAndVisible()
}
Swift 4+:和 Swift 5+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
let nav1 = UINavigationController()
let mainView = ViewController(nibName: nil, bundle: nil) //ViewController = Name of your controller
nav1.viewControllers = [mainView]
self.window!.rootViewController = nav1
self.window?.makeKeyAndVisible()
}
这篇关于以编程方式创建一个 navigationController (Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式创建一个 navigationController (Swift)


基础教程推荐
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01