以编程方式创建navigationController(Swift) [英] Creating a navigationController programmatically (Swift)

查看:87
本文介绍了以编程方式创建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个viewcontroller。当然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:

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 3+:和Swift 4 +

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆