swift-碰到的问题

发布时间:2023年12月30日

如何让工程不使用storyboard和scene

在这里插入图片描述
删除info.plist里面的Application Scene mainifest
删除SceneDelegate.swift
删除AppDelegate.swift里面的这两个方法

 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
 func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {

然后在appDelegate,swift里面添加

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?//添加window

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        window = UIWindow(frame: UIScreen.main.bounds)  
        // 设置根视图控制器
        var VC = UIViewController()
        VC.view.backgroundColor = UIColor.blue
          let rootViewController = VC  // 替换为你的视图控制器
          window?.rootViewController = rootViewController
        window?.makeKeyAndVisible()//让window可以被看见
        
        return true
    }

}


文章来源:https://blog.csdn.net/qq_43535469/article/details/135304973
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。