【问题标题】:SwiftUI SceneDelegate IssueSwiftUI SceneDelegate 问题
【发布时间】:2019-07-02 21:50:14
【问题描述】:

SceneDelegate.swift 内,以下代码返回错误消息“使用未解析的标识符'ContentView';您的意思是'ContentMode'吗?”。

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options 
connectionOptions: UIScene.ConnectionOptions) {
    let window = UIWindow(frame: UIScreen.main.bounds)
    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()
}

此错误会导致程序构建失败。令人惊讶的是,当我使用完全相同的 SceneDelegate.swift 创建一个新项目时,ContentView 没有问题。

如果我将 ContentView 更改为 ContentMode,它会返回错误 'ContentMode' cannot beConstructed because it has no access initializers"。

还有其他人遇到过这个问题吗?只是好奇我应该从哪里开始寻找或者我做错了什么。

【问题讨论】:

  • 请同时附上您的ContentView 代码。

标签: ios swiftui


【解决方案1】:

想出了这个。如果其他人好奇,我更改了ContentView.swift 文件名,但没有在SceneDelegate.swift 中更新它。

因此,如果您将ContentView.swift 文件更改为BetterNameView.swift,则需要将SceneDelegate.swift 中的上述代码从ContentView() 更新为BetterNameView()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 2021-08-23
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多