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

时间:2015-11-11 02:06:53

标签: ios swift

我没有启用故事板。我正在初始化viewcontroller,如下所示:

var customViewController = CustomViewController();

然后这样说customViewController是零:

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

1 个答案:

答案 0 :(得分:3)

我尝试并成功了

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

并按

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

在CustomViewController中有什么内容吗?