ios - 创建新的 View Controller

标签 ios swift xcode user-interface uiviewcontroller

我正在尝试以编程方式创建一个新的 View Controller ,而不是使用 Xcode 上的 Storyboard。我对编码很陌生,不明白我必须在框架所在的括号中加上什么值。代码全部在应用程序委托(delegate)上,请您帮忙。

    let layout = UICollectionViewFlowLayout()

    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    window?.rootViewController = UINavigationController(rootViewController: Homecontroller(frame: -, collectionViewLayout: layout))

最佳答案

检查这个

window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    let layout = UICollectionViewFlowLayout()
     window?.rootViewController = UINavigationController(rootViewController: HomeController(collectionViewLayout: layout))

你的 HomeController 应该是这样的

class HomeController: UICollectionViewController {

override func viewDidLoad() {
    super.viewDidLoad()
   }
}

关于ios - 创建新的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51101537/

相关文章:

ios - 是否可以使用 swift 将用户输入输出到 .csv?

Mac OS X 10.6 上缺少 Python.h 头文件

xcode - 后台循环结束后运行代码

ios - 无法转换类型 'Bird' 的值,类型 'to expected argument type ' SKTexture'

ios - 我的应用程序在 iOS 4.3 上崩溃,但只有从 App Store 下载时才会崩溃

swift - 我如何创建一个函数来从 Swift 中的年份返回世纪?

ios - Spotify 登录 URL 被 .canHandle 方法拒绝

objective-c - 将 Storyboard中的 UIViewController 更改为 UITableViewController?

ios - NSURLConnection 在 HTTP 401 后不会调用 NSURLConnectionDelegate 身份验证方法

iOS - 全屏时 Youtube 播放器 Controller 栏颜色