簡體   English   中英

“在 Swift 的 scope 中找不到‘ContentView’

[英]"Cannot find 'ContentView' in scope in Swift

我剛剛學習 Swift,我創建了這個需要 UIKit 的入門項目,但是每當我運行代碼時,都會出現以下錯誤:

"Cannot find 'ContentView' in scope in Swift

這是代碼:

import UIKit


class ViewController: UIViewController {
    
    
    private let imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFill
        imageView.backgroundColor = .white
        return imageView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemPink
    }
    
    
}
You might need to clean the Build folder, ie, use the keyboard shortcut Shift + Command + K or via the Menu “Product > Clean Build Folder”
You might need to restart Xcode.
You might need to restart your Mac

或者

您是否在 AppDelegate/SceneDelegete 手動加載視圖控制器?

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = ViewController()
        window?.makeKeyAndVisible()
        return true
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM