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)
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- UITextView 内容插图 2022-01-01
- URL编码Swift iOS 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
