我正在尝试构建自己的时间管理应用,并且在我的AppDelegate.swift
中遇到以下错误。
我已经尝试在代码中查找拼写错误或其他错误,但未成功。
应该是一个基本的Use of unresolved Identifier
错误,但由于某种原因我找不到解决方法。
第一个问题^^让我知道您何时需要更多信息。感谢您的帮助!
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.main.bounds)
if let window = self.window {
window.backgroundColor = UIColor.white
let nav = UINavigationController()
let mainView = ViewController()
nav.viewControllers = [mainView]
window.rootViewController = nav
window.makeKeyAndVisible()
}
return true
}
.
.
.
// Other default AppDelegate functions
}
Use of unresolved identifier 'ViewController'
编辑: ViewController代码
import UIKit
enum MyTheme {
case light
case dark
}
class ViewController: UIViewController {
var theme = MyTheme.dark
override func viewDidLoad() {
super.viewDidLoad()
self.title = "My Calender"
self.navigationController?.navigationBar.isTranslucent=false
self.view.backgroundColor=Style.bgColor
view.addSubview(calenderView)
calenderView.topAnchor.constraint(equalTo: view.topAnchor, constant: 10).isActive=true
calenderView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -12).isActive=true
calenderView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 12).isActive=true
calenderView.heightAnchor.constraint(equalToConstant: 365).isActive=true
let rightBarBtn = UIBarButtonItem(title: "Light", style: .plain, target: self, action:
#selector(rightBarBtnAction))
self.navigationItem.rightBarButtonItem = rightBarBtn
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
calenderView.myCollectionView.collectionViewLayout.invalidateLayout()
}
@objc func rightBarBtnAction(sender: UIBarButtonItem) {
if theme == .dark {
sender.title = "Dark"
theme = .light
Style.themeLight()
} else {
sender.title = "Light"
theme = .dark
Style.themeDark()
}
self.view.backgroundColor=Style.bgColor
calenderView.changeTheme()
}
let calenderView: CalenderView = {
let v=CalenderView(theme: MyTheme.dark)
v.translatesAutoresizingMaskIntoConstraints=false
return v
}()
}