简体   繁体   English

如果没有Storyboard,如何初始化自定义ViewController?

[英]How do I initialize a custom ViewController when there's no Storyboard?

I do not have storyboard enabled. 我没有启用故事板。 I am initializing the viewcontroller like so: 我正在初始化viewcontroller,如下所示:

var customViewController = CustomViewController();

then doing this says customViewController is nil: 然后这样做说customViewController是零:

self.navigationController!.pushViewController(customViewController, animated: true)

I tried and succeeded 我试过并成功了

import Foundation
class MyCustomViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.redColor()
    }
}

and push 并推

var customViewController = MyCustomViewController()
self.navigationController?.pushViewController(customViewController, animated: true)

have anything in your CustomViewController ? 你的CustomViewController中有什么东西?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用它的 Coder 从 storyboard 初始化 ViewController - How to initialize ViewController from storyboard using it's Coder 如何使用给定的根ViewController和初始ViewController实例化情节提要? - How do I instantiate a storyboard with a given root viewcontroller and initial viewcontroller? 没有情节提要时实例化ViewController - Instantiating a ViewController when there's no storyboard 当我在app didFinishLaunchingWithOptions中收到UIApplicationLaunchOptionsLocationKey时,我是否初始化viewController? - Do I initialize the viewController when I receive UIApplicationLaunchOptionsLocationKey in app didFinishLaunchingWithOptions? 如何从情节提要中的NIB子视图选择视图控制器 - How do I segue from a NIB subview to a viewcontroller in the storyboard xcode storyboard容器视图 - 如何访问viewcontroller - xcode storyboard Container View - How do I access the viewcontroller 如何在Storyboard中使用ViewController的自定义init - How to use custom init of ViewController in Storyboard 如何在同一ViewController中初始化两个NSObject实例-Swift - How Do I Initialize Two Instances of NSObject in the same ViewController - Swift 如何在ViewController中初始化实例变量和属性 - How do I initialize instance variables and properties in the ViewController 故事板中的自定义表ViewController - Custom Table ViewController in a StoryBoard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM