gpt4 book ai didi

iOS编程: Class and Instance

转载 作者:行者123 更新时间:2023-12-01 18:39:58 25 4
gpt4 key购买 nike

我想我可能会问一个愚蠢的问题,但这确实让我困惑了一段时间。

我是 iOS 开发的初学者,我在网上看到的例子是人们总是在 viewController 的类中编写代码。

但是,根据我在 C++ 中的经验,我认为类只是一个可重用的模板。您只能在初始化后使用它。
所以执行工作的是实例。

我的问题是何时/谁在应用程序中创建 viewController 实例?

最佳答案

我想你指的是模板 ViewController ,例如,总是带有一个新的单页应用程序项目。

一旦您的应用程序完成启动,它就会在“幕后”创建,但它的基本作用如下:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

window = UIWindow(frame: UIScreen.main.bounds)

window?.makeKeyAndVisible()

window?.rootViewController = ViewController();
return true
}

事实上,如果您想删除 Storyboard 并完全以编程方式工作,除了清除 之外,这就是您需要做的事情。主界面您项目的一般信息中的信息如下:

Leave the Main Interface info blank

如果你想展示另一个自定义 ViewController类,你可以从另一个 ViewController如在
let secondViewController = MyCustomViewController()
// this line will place the MyCustomViewController instance on top of the current ViewController
present(secondViewController, animated: true, completion: nil)

我希望我能帮上忙!

关于iOS编程: Class and Instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44810002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com